【问题标题】:Query with match to get all values for a given field! ElasticSearch使用匹配查询以获取给定字段的所有值!弹性搜索
【发布时间】:2019-04-23 15:36:07
【问题描述】:

我是弹性搜索的新手,想为特定字段的所有值编写查询?我的意思是,假设我有一个字段“Number”和“change_manager_group”,是否有一个查询来执行列出所有“change_manager_group = Change Managers - 2”的数字

  {
   "took" : 2,
   "timed_out" : false,
   "_shards" : {
    "total" : 10,
    "successful" : 10,
    "skipped" : 0,
    "failed" : 0
    },
    "hits" : {
      "total" : 1700,
      "max_score" : 1.0,
      "hits" : [
        {
    "_index" : "test-tem-changes",
    "_type" : "_doc",
    "_id" : "CHG0393073_1554800400000",
    "_score" : 1.0,
    "_source" : {
      "work_notes" : "",
      "priority" : "4 - Low",
      "planned_start" : 1554800400000,
      "Updated_by" : "system",
      "Updated" : 1554819333000,
      "phase" : "Requested",
      "Number" : "CHG0312373",
      "change_manager_group" : "Change Managers - 1",
      "approval" : "Approved",
      "downtime" : "false",
      "close_notes" : "",
      "Standard_template_version" : "",
      "close_code" : null,
      "actual_start" : 1554819333000,
      "closed_by" : "",
      "Type" : "Normal"
    }
  },
  {
    "_index" : "test-tem-changes",
    "_type" : "_doc",
    "_id" : "CHG0406522_0",
    "_score" : 1.0,
    "_source" : {
      "work_notes" : "",
      "priority" : "4 - Low",
      "planned_start" : 0,
      "Updated_by" : "svcmdeploy_automation",
      "Updated" : 1553320559000,
      "phase" : "Requested",
      "Number" : "CHG041232",
      "change_manager_group" : "Change Managers - 2",
      "approval" : "Approved",
      "downtime" : "false",
      "close_notes" : "Change Installed",
      "Standard_template_version" : "",
      "close_code" : "Successful",
      "actual_start" : 1553338188000,
      "closed_by" : "",
      "Type" : "Automated"
    }
  },
  {
    "_index" : "test-tem-changes",
    "_type" : "_doc",
    "_id" : "CHG0406526_0",
    "_score" : 1.0,
    "_source" : {
      "work_notes" : "",
      "priority" : "4 - Low",
      "planned_start" : 0,
      "Updated_by" : "svcmdeploy_automation",
      "Updated" : 1553321854000,
      "phase" : "Requested",
      "Number" : "CHG0412326",
      "change_manager_group" : "Change Managers - 2",
      "approval" : "Approved",
      "downtime" : "false",
      "close_notes" : "Change Installed",
      "Standard_template_version" : "",
      "close_code" : "Successful",
      "actual_start" : 1553339629000,
      "closed_by" : "",
      "Type" : "Automated"
    }
  },

我在谷歌上搜索了一下后尝试了这个,但是错误了

curl -XGET  "http://localhost:9200/test-tem-changes/_search?pretty=true" -H 'Content-Type: application/json' -d '
> {
>     "query" : { "Number" : {"query" : "*"} }
> }
> '

我在这里错过了什么?

【问题讨论】:

    标签: elasticsearch nested


    【解决方案1】:

    要获取您想要使用Term Querychange_manager_group ==Change Managers - 2 的所有文档。下面我将它包装在 filter 上下文中,以便它更快(不得分相关性)。

    如果change_manager_group 不是keyword 映射字段,您可能必须使用change_manager_group.keyword,具体取决于您的映射。

    GET test-tem-changes/_search
    {
      "query": {
        "bool": {
          "filter": {
            "term": {
              "change_manager_group": "Change Managers - 2"
            }
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多