简体   繁体   English

如何从elasticsearch返回具有该值的字段

[英]How to return field which has that value from elasticsearch

I have a document like this 我有这样的文件

{
    "field_1": ["val_1", "val_2"],
    "field_2": ["val_21", "val_14"],
    "field_3": ["val_6", "val_9"]
}

If I search for "val_1", I want to get "field_1" and if I search for "val_9" I want to get "field_3" from elasticsearch response. 如果我搜索“ val_1”,我想获取“ field_1”,如果我搜索“ val_9”,我想从elasticsearch响应中获取“ field_3”。 So to know which field the value matched in. 因此要知道该值与哪个字段匹配。

How can i do that in elasticsearch. 我如何在Elasticsearch中做到这一点。

I am using: 我在用:

Version: 2.3.2, Build: b9e4a6a/2016-04-21T16:03:47Z, JVM: 1.8.0_91
POST /www/test/1
{"field_1":["val_1","val_2"],"field_2":["val_21","val_14"],"field_3":["val_6","val_9"]}

GET /www/test/_search
{
  "query": {
    "multi_match": {
      "query": "val_1",
      "fields": ["field_*"]
    }
  },
  "highlight": {
    "fields": {
      "field_*":{}
    }
  }
}

And for this data and query, this would be the output: 对于此数据和查询,将是输出:

  "hits": [
     {
        "_index": "www",
        "_type": "test",
        "_id": "1",
        "_score": 0.058849156,
        "_source": {
           "field_1": [
              "val_1",
              "val_2"
           ],
           "field_2": [
              "val_21",
              "val_14"
           ],
           "field_3": [
              "val_6",
              "val_9"
           ]
        },
        "highlight": {
           "field_1": [
              "<em>val_1</em>"
           ]
        }
     }
  ]

So, for highlighting you get a separate section - highlight - where, depending on the queries you get the highlighted value in a certain field. 因此,对于突出显示,您将获得一个单独的部分- highlight -在其中,根据查询,您将在某个字段中获得突出显示的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM