3

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

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

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

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

1 回答 1

4

您可以使用多搜索 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" } } } }
于 2018-02-13T18:11:26.530 回答