如何从elasticsearch查询结果中搜索\u源中的特定值?

93ze6v8z  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(1)|浏览(467)

我通过ElasticSearch收集日志。我通过查询查询结果。
使用以下查询进行查询时

GET test/_search
{
  "query": {
    "match_all":{
    }
  }
}

调查结果如下。

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 100,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test",
        "_id" : "1a2b3c4d5e6f",
        "_score" : 1.0,
        "_source" : {
          "team" : "Marketing"
          "number" : "3"
          "name" : "Mark"
        }
      },
      {
        "_index" : "test",
        "_id" : "1a2b3c4d5e66",
        "_score" : 1.0,
        "_source" : {
          "team" : "HR"
          "number" : "1"
          "name" : "John"
        }
      }, 
      ........

但是,我想问以下问题。(具体数值的内部点击)

{
    "name": "Mark"
},
{
    "name": "John"
},

那么,如何查询一个特定的值?
谢谢。

ncecgwcz

ncecgwcz1#

您可以简单地使用es的源代码过滤功能,因此在您的情况下,您的查询将如下所示:

{
    "_source": "name",
    "query": {
        "match_all": {}
    }
}

它会返回如下搜索结果

"hits": [
            {
                "_index": "64214413",
                "_type": "_doc",
                "_id": "1",
                "_score": 1.0,
                "_source": {
                    "name": "Mark"
                }
            },
            {
                "_index": "64214413",
                "_type": "_doc",
                "_id": "2",
                "_score": 1.0,
                "_source": {
                    "name": "John"
                }
            }
        ]

相关问题