多索引搜索(自动完成)

Multi-Index search (autocomplete)

我有四个名为城市、地区、国家和酒店的索引,它们有一个名为 name 的共同字段我想搜索这些索引并获得用于自动完成的结果。此外,我无法使用 Logstash 中的 JDBC 输入和重新索引 API 创建具有单个索引的多类型,只是由于 Elasticsearch 中每个索引更改一个文档 6.x 这是一个示例索引搜索;

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

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

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

您可以使用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" } } } }