如何识别结果来自哪个索引



我知道我们可以在弹性搜索中搜索多个索引,但我知道特定的搜索结果是否属于哪个索引吗?

根据我的要求,我想提供对不同类型/索引的全局搜索,但用户应该知道搜索来自哪个索引/上下文,因为这将帮助他们正确地将结果与上下文相关联

Elasticsearch 在搜索响应中添加了一些字段。有些是_index_type.您可以将它们用于您的目的。

因此,示例 Elasticsearch 响应如下所示:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 19,
    "max_score": 1.1,
    "hits": Array[10][
      {
        "_index": "first_index_name",
        "_type": "first_type_of_first_index",
        "_id": "doc-id-125125422",
        "_score": 1.1,
        "_source": { /*here is your indexed document*/ }
      },
      {
        "_index": "second_index_name",
        "_type": "first_type_of_second_index",
        "_id": "doc-id-212452314",
        "_score": 0.9,
        "_source": {...}
      },
      ...
    ]
  }
}

最新更新