search - 在 ElasticSearch 中找到文本的返回字段

标签 search field elasticsearch

我需要帮助。我在 elasticsearch 1.6 上有这些文档

{
 "name":"Sam",
 "age":25,
 "description":"Something"
},
{
 "name":"Michael",
 "age":23,
 "description":"Something else"
}

使用此查询:

GET/MyIndex/MyType/_search?q=Michael

弹性返回这个对象:

{
 "name":"Michael",
 "age":23,
 "description":"Something else"
}

... 没错,但我想获得找到文本“Michael”的确切键。那可能吗?非常感谢。

最佳答案

我假设您指的是文档 ID。
索引以下文档时:

PUT my_index/my_type/1
{
     "name":"Sam",
     "age":25,
     "description":"Something"
}

PUT my_index/my_type/2
{
     "name":"Michael",
     "age":23,
     "description":"Something else"
}

并搜索:

GET /my_index/my_type/_search?q=Michael

您将收到以下响应:

{
   "took": 8,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0.15342641,
      "hits": [
         {
            "_index": "my_index",
            "_type": "my_type",
            "_id": "2",
            "_score": 0.15342641,
            "_source": {
               "name": "Michael",
               "age": 23,
               "description": "Something else"
            }
         }
     ]
   }
}

如您所见,hits 数组包含每个搜索命中的对象。
在这种情况下,Michael 的关键是“_id”:“2”,这是他的文档 ID。

希望对您有所帮助。

关于search - 在 ElasticSearch 中找到文本的返回字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31009342/

相关文章:

java - hibernate 如何访问私有(private)字段?

elasticsearch动态字段嵌套检测

hadoop - pig 商店输出到ElasesticSearch遇到错误

c - 查找两个数组中每个索引处不匹配的元素

algorithm - 查找黑盒函数的第一个根,或同一函数的任何负值

mysql - 复杂的MySQL语句来列出钓鱼排行榜?

ruby-on-rails - 在 Ruby on Rails 中隐藏字段

c# - 使用Nest + C#在 Elasticsearch 中查找具有空字段/附件的文档

php - 使用mysql搜索多个表?

android - 如何实现像 facebook 这样的搜索,它将通过我的 android 搜索我的联系人?