【问题标题】:Elastic search query for name / value pair columns pull名称/值对列的弹性搜索查询
【发布时间】:2019-01-17 11:15:06
【问题描述】:

我们在弹性搜索中有一个包含多个名称/值对部分的文档,我们希望仅根据名称列值获取值。

"envelopeData": {
  "envelopeName": "Bills",
  "details": {
    "detail": [
      {
        "name": "UC_CORP",
        "value": "76483"
      },
      {
        "name": "UC_CYCLE",
        "value": "V"
      }    

我们预计只有 76483 作为基于名称等于 UC_CORP

的结果

【问题讨论】:

标签: elasticsearch kibana elasticsearch-query aws-elasticsearch


【解决方案1】:

如果字段 envelopeData.details.detailnested 类型,那么您可以对嵌套路径上的所需名称执行匹配查询,并且可以使用 inner_hits 来获取值。

将字段 envelopeData.details.detail 映射为嵌套(如果未嵌套):

PUT stackoverflow
{
  "mappings": {
    "_doc": {
      "properties": {
        "envelopeData.details.detail": {
          "type": "nested" 
        }
      }
    }
  }
}

然后您可以使用 inner_hits 执行以下查询以获取值:

GET stackoverflow/_search
{
  "_source": "false", 
  "query": {
    "nested": {
      "path": "envelopeData.details.detail",
      "query": {
        "match": {
          "envelopeData.details.detail.name.keyword": "UC_CORP"
        }
      }, 
      "inner_hits": {
        "_source": "envelopeData.details.detail.value"
      }
    }
  }
}

哪个输出:

{
  "_index": "stackoverflow",
  "_type": "_doc",
  "_id": "W5GUW2gB3GnGVyg-Sf4T",
  "_score": 0.6931472,
  "_source": {},
  "inner_hits": {
    "envelopeData.details.detail": {
      "hits": {
        "total": 1,
        "max_score": 0.6931472,
        "hits": [
          {
            "_index": "stackoverflow",
            "_type": "_doc",
            "_id": "W5GUW2gB3GnGVyg-Sf4T",
            "_nested": {
              "field": "envelopeData.details.detail",
              "offset": 0
            },
            "_score": 0.6931472,
            "_source": {
              "value": "76483"  -> Outputs value only
            }
          }
        ]
      }
    }
  }
}

【讨论】:

  • 我认为我的数据不是嵌套类型。低于错误。 "caused_by": { "type": "illegal_state_exception", "reason": "[nested] 路径 [notificationJson.envelopeData.details.detail] 下的嵌套对象不是嵌套类型" }
  • GET delivery/_search { "_source": "false", "query": { "nested" : { "path" : "notificationJson", "query" : { "bool" : { "必须”:[{“匹配”:{“notificationJson.envelopeData.details.detail.name”:“UC_CORP”}}]}},“inner_hits”:{“_source”:“notificationJson.envelopeData.details.detail.value " } } } }
  • 在输出中我得到所有值字段,但我只想要匹配的一个 _source": { "envelopeData": { "details": { "detail": [ { "value": "e9556" }, { "值": "A"
猜你喜欢
  • 2020-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-09
  • 1970-01-01
  • 1970-01-01
  • 2021-08-08
相关资源
最近更新 更多