gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 00:57:46 25 4
gpt4 key购买 nike

鉴于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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com