多索引搜索(自动完成)

时间:2018-02-13 16:43:26

标签: elasticsearch elasticsearch-6

我有四个指数,称为城市,地区,国家和酒店,他们有共同的名称,名称我想搜索这些索引,并获得在自动完成中使用的结果。此外,我无法使用Logstash和reindex API中的JDBC输入创建具有单个索引的多类型,因为Elasticsearch 6.x中每个索引更改一个文档这里是单索引搜索的示例;

[^a-zA-Z0-9-_\\.]

我想对多指数情况做同样的事情。以下不起作用:

GET /hotels/hotels/_search
{
  "query": {
    "match": {
      "name": {
        "query": "term",
        "operator": "and"
      }
    }
  }
}

1 个答案:

答案 0 :(得分:4)

您可以使用Multi Search API。这样,您可以对不同的索引提供多个查询。例如:

GET _msearch
{"index" : "hotels"}
{ "query": { "match": { "name": { "query": "term", "operator": "and" } } } }
{"index" : "cities"}
{ "query": { "match": { "name": { "query": "term", "operator": "and" } } } }
{"index" : "countries"}
{ "query": { "match": { "name": { "query": "term", "operator": "and" } } } }
{"index" : "regions"}
{ "query": { "match": { "name": { "query": "term", "operator": "and" } } } }
相关问题