是时候用 ES 拯救发际线啦

elasticsearch 多索引搜索返回结果问题

Elasticsearch | 作者 chenygs | 发布于2019年09月29日 | 阅读数:3319

现在想做一个全文搜索,有若干索引库,其中有的索引库用到了嵌套对象,这个嵌套对象也是要进行文字搜索的,但是不知道怎么搜索和排序,求大神指点一下,谢谢
已邀请:

ciaohi

赞同来自:

好问题

ting44

赞同来自:

我之前做个差不多的需求,同时搜索多个索引,将命中结果一起返回。我的思路使用线程组并发查询几个索引,使用同位器组装结果

- Elasticsearch,php

赞同来自:

给这多个相同结构的索引创建索引别名,查询的时候就用这个别名查。嵌套里面的数据查询用这样的查询方式:
GET /_search
{
  "query": {
    "nested": { 
      "path": "comments",
      "filter": {
        "range": {
          "comments.date": {
            "gte": "2014-10-01",
            "lt":  "2014-11-01"
          }
        }
      }
    }
  },
  "sort": {
    "comments.stars": { 
      "order": "asc",   
      "mode":  "min",   
      "nested_filter": { 
        "range": {
          "comments.date": {
            "gte": "2014-10-01",
            "lt":  "2014-11-01"
          }
        }
      }
    }
  }
}

chenygs

赞同来自:

目前采用的方式:
GET /index1,index2/_search
{
"_source": [
"id",
"siteType",
"publishDate",
"offDate",
"isShow",
"status",
"infoDetail.title",
"infoDetail.subtitle",
"infoDetail.fullTitle",
"infoDetail.metaDescription",
"infoAuthors.id",
"infoAuthors.author.id",
"infoAuthors.author.authorname",
"infoAttributes.id",
"infoAttributes.attribute.id",
"infoAttributes.attribute.siteType",
"infoAttributes.attribute.nodeId",
"infoAttributes.attribute.type",
"infoAttributes.attribute.name",
"infoTags.id",
"infoTags.tagIndex",
"infoTags.tag.id",
"infoTags.tag.name",
"infoClobs.id",
"infoClobs.key",
"nickName"
],
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"range": {
"publishDate": {
"lte": "now"
}
}
},
{
"term": {
"isShow": "T"
}
},
{
"term": {
"status": "A"
}
}
],
"should": [
{
"nested": {
"path": "infoDetail",
"query": {
"multi_match": {
"query": "脑室心房分流术病例分享",
"fields": [
"infoDetail.title^2.0",
"infoDetail.subtitle^1.2",
"infoDetail.fullTitle^1.2",
"infoDetail.metaDescription^1.2"
]
}
}
}
}
]
}
},
{
"multi_match": {
"query": "脑室心房分流术病例分享",
"fields": [
"nickName^2.1"
]
}
}
]
}
},
"from": 0,
"size": 10
}
技术不够,基础来凑。哈哈,其实就是单纯的 bool查询  采用 bool-should  每个索引查询对应一个should对象

要回复问题请先登录注册