elasticsearch - 正确查询ES中类似嵌套的属性(但不包含嵌套类型)

标签 elasticsearch nest

鉴于ES 1.7中的本文档

 {
                  "_index": "prod",
                  "_type": "customerpropertieses",
                  "_id": "215c4bd7-7611-4c6a-8681-ef3b318613a0",
                  "_source": {
                    "properties": [
                      {
                        "extentionPropertyId": 7,
                        "propertyName": "Video Introduction",
                        "value": "bla"
                      },
                      {
                        "extentionPropertyId": 8,
                        "propertyName": "Guide Exp"
                      },
                    ],
                    "id": "215c4bd7-7611-4c6a-8681-ef3b318613a0",
                    "parentId": "2222"
                  } }

我想找到一个查询,该查询表明propertyName和相同花括号中的值匹配某些值,然后返回该customerproperties文档。

现在,我可能在以下查询中做错了事,因为ANY propertyName匹配查询而ANY值匹配查询时,它返回了customerpropertieses文档。基本上,我想将propertyName和value的分组强制来自相同的“对象索引”

无法正常运行的ES查询
"query":{
            "type": "customerpropertieses",
                "query": {
                  "bool": {
                    "must": [
                      {
                        "bool": {
                          "must": [
                            {
                              "match": {
                                "propertyName": {
                                  "query": "Guide Exp"
                                }
                              }
                            },
                            {
                              "match": {
                                "value": {
                                  "query": "bla"
                                }
                              }
                            }
                          ]
                        }
                      }
                    ]
                  }
                }       }

我需要嵌套类型吗?

最佳答案

简短的答案:您确实需要使用嵌套文档。
稍长一点:在内部,ES将这些元素“扁平化”,使其看起来像Lucene索引中那样:

{
   extentionPropertyId: [7, 8],
   propertyName: ["Video Introduction", "Guide Exp"],
   value: ["bla"]
}

如您所见,每个“对象”之间的链接都丢失了。

这是更长的解释
https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html

关于elasticsearch - 正确查询ES中类似嵌套的属性(但不包含嵌套类型),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41858120/

相关文章:

c# - Elasticsearch索引文档,但下一个查询返回0个匹配

elasticsearch - Kibana 中有缺陷的 token 配置为使用 SPNEGO

c# - 无法在我的 A.CallTo FakeItEasy 方法中获得正确的参数

c# - 如何在.net nest中更新现有已过滤的Elasticsearch查询

c# - 在Elasticsearch的查询DSL中使用 `MatchPhrasePrefix`

c# - Elastic Search Nest-比较两个字段

elasticsearch - 合并 hunspell 过滤器后在 elasticSearch 中完全匹配

elasticsearch - 如何在 Kibana 中将百分比显示为指标?

asp.net-mvc - Serilog 不会将日志写入 AWS Elasticsearch Service

c# - 如何在一个 Nest 查询中根据条件获取范围大于或小于?