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

标签 java elasticsearch

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

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

最佳答案

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": {...}
      },
      ...
    ]
  }
}

关于java - 如何识别结果来自哪个索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48575905/

相关文章:

elasticsearch - ElasticSearch中的html_strip字符过滤器将标签替换为换行符?

elasticsearch - Elasticsearch 日期字段中的空字符串?

elasticsearch - Elasticsearch 中的桶脚本java api

java - Java -Xmx 在大量 ram 上的奇怪行为

java - SocketChannel 问题

java - 如何设置 onItemClick 方法以显示我在 ListView 中单击的文本?

java - JMX 可扩展性 : can it be used to manage 400+ instances?

elasticsearch - 如何从 ElasticSearch 记录中聚合匹配的前缀/短语?

java - Android Studio 数据绑定(bind)错误,无法解析符号

elasticsearch - 在 Elasticsearch 中将字符串的默认映射更改为 "not analyzed"