正确查询ES中嵌套的类似属性(但没有嵌套类型)

时间:2017-01-25 17:40:36

标签: 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和值在相同的花括号中匹配某些值,则返回该customerpropertieses文档。

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

ES查询无法正常工作

"query":{
            "type": "customerpropertieses",
                "query": {
                  "bool": {
                    "must": [
                      {
                        "bool": {
                          "must": [
                            {
                              "match": {
                                "propertyName": {
                                  "query": "Guide Exp"
                                }
                              }
                            },
                            {
                              "match": {
                                "value": {
                                  "query": "bla"
                                }
                              }
                            }
                          ]
                        }
                      }
                    ]
                  }
                }       }

我需要嵌套类型吗?

1 个答案:

答案 0 :(得分:2)

简短回答:你确实需要使用嵌套文档。 稍微长一些:在内部,ES"变平"这些在Lucene索引中看起来像那样:

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

正如您所看到的,每个"对象"之间的链接失去了。

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

相关问题