我使用Query来获取所有的sub_attributes.id(13,15,19). bu在结果中应该只获取id,其中sub_attributes.id为13,15,&19.不是我提到的id.应该获取部分索引值,并且使用must_not,不获取我期望的确切结果。
下面是我用来获取值的查询,
查询
{
"query": {
"bool": {
"must": [
{
"terms": {
"sub_attributes.id": [13, 15, 19]
}
}
]
}
}
}
字符串
结果:
{
"_index": "attrib",
"_id": "id1",
"_score": 1.0,
"_source": {
"product_attribute_id": 5,
"main_attribute_name": "Grades"
"sub_attributes": [
{
"id": 13,
"attribute_label": null,
"attribute_value": "Grade A"
},
{
"id": 14,
"attribute_label": null,
"attribute_value": "Grade B"
}
]
}
},
{
"_index": "attrib",
"_id": "id2",
"_score": 1.0,
"_source": {
"product_attribute_id": 6,
"main_attribute_name": "Operations",
"sub_attributes": [
{
"id": 15,
"attribute_label": null,
"attribute_value": "Building"
},
{
"id": 16,
"attribute_label": null,
"attribute_value": "Sliding"
}
{
"id": 19,
"attribute_label": null,
"attribute_value": "Double fold"
}
]
}
}
型
预期结果:
{
"_index": "attrib",
"_id": "id1",
"_score": 1.0,
"_source": {
"product_attribute_id": 5,
"main_attribute_name": "Grades",
"sub_attributes": [
{
"id": 13,
"attribute_label": null,
"attribute_value": "Grade A"
}
]
}
},
{
"_index": "attrib",
"_id": "id2",
"_score": 1.0,
"_source": {
"product_attribute_id": 6,
"main_attribute_name": "Operations"
"sub_attributes": [
{
"id": 15,
"attribute_label": null,
"attribute_value": "Building"
},
{
"id": 19,
"attribute_label": null,
"attribute_value": "Double fold"
}
]
}
}```
want to know which term needs to be used to fetch the expected result
型
1条答案
按热度按时间0md85ypi1#
Tldr;
我不相信你可以。Elasticsearch允许过滤文档,但不能过滤文档的子部分。
解决方案
你可以修改你的文档,看起来像这样:
字符串
这将创建更多的文档,但更容易实现你想要的。