【发布时间】:2020-03-06 10:56:11
【问题描述】:
我想查找提交的 preices.info 等于 null 的文档。价格是一个嵌套字段 查询示例如下所示
{
"query": {
"bool": {
"must": [
{
"term": {
"doc_type": "supnom"
}
},
{
"term": {
"is_linking_disabled": false
}
},
{
"has_parent": {
"parent_type": "sup",
"query": {
"bool": {
"must": [
{
"term": {
"id": 89634082
}
}
]
}
}
}
},
{
"bool": {
"should": [
{
"bool": {
"must": [
{
"term": {
"folder_type": 0
}
},
{
"term": {
"folder": "NULL"
}
},
{
"term": {
"is_folder": true
}
},
{
"term": {
"is_folder_hybrid": true
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"folder_type": 1
}
},
{
"term": {
"folder": "89634082-NULL"
}
},
{
"term": {
"is_folder": true
}
},
{
"term": {
"is_folder_hybrid": true
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"is_folder": false
}
},
{
"term": {
"folder_hybrid": "NULL"
}
},
{
"nested": {
"path": "prices",
"query": {
"terms": {
"prices.id_prcknd": [
22215
]
}
}
}
}
]
}
},
{
"bool": {
"must_not": [
{
"nested": {
"path": "prices",
"query": {
"bool": {
"filter": {
"exists": {
"field": "prices.info"
}
}
}
}
}
}
]
}
}
]
}
}
],
"must_not": [],
"should": []
}
},
"size": 70,
"from": 0,
"_source": true,
"sort": [
{
"is_folder": {
"order": "desc"
}
},
{
"title_low.order": {
"order": "asc"
}
}
]
}
无论如何,我得到的结果文档中的价格信息字段不为空
{
"took": 65,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 7,
"max_score": null,
"hits": [
{
"_index": "supnoms",
"_type": "doc",
"_id": "supnom-108340976",
"_score": null,
"_routing": "1",
"_source": {
"codes": null,
"folder": null,
"folder_hybrid": null,
"folder_hybrid_type": 0,
"folder_type": null,
"id": "108340976",
"id_supplier": 89634082,
"is_folder": false,
"is_folder_hybrid": null,
"is_linking_disabled": false,
"manufacturer": {
"id": null,
"title": null
},
"market_nom": {
"folder": null,
"id": null
},
"path_market": {
"parents": null,
"pids": null,
"strpath": null
},
"path_supnom": {
"parents": null,
"pids": null,
"strpath": null
},
"prices": [
{
"currency": "RUR",
"id_offer": 605966502,
"id_prcdoc": 42040,
"id_prcknd": 22215,
"info": {
"Price": "По запросу"
},
"min_order": null,
"sell_by": null,
"value": "По запросу"
}
],
"sup_code": "c39f81c9-1a69-3a7d-9e04-5f4e124242e7",
"title": "баклажан UPC",
"title_low": "баклажан upc",
"_join_field_name": "doc_type",
"doc_type": {
"name": "supnom",
"parent": "sup-89634082"
}
},
"sort": [
0,
"баклажан upc"
]
},
{
"_index": "supnoms",
"_type": "doc",
"_id": "supnom-108340975",
"_score": null,
"_routing": "1",
"_source": {
"codes": null,
"folder": null,
"folder_hybrid": null,
"folder_hybrid_type": 0,
"folder_type": null,
"id": "108340975",
"id_supplier": 89634082,
"is_folder": false,
"is_folder_hybrid": null,
"is_linking_disabled": false,
"manufacturer": {
"id": null,
"title": null
},
"market_nom": {
"folder": null,
"id": null
},
"path_market": {
"parents": null,
"pids": null,
"strpath": null
},
"path_supnom": {
"parents": null,
"pids": null,
"strpath": null
},
"prices": [
{
"currency": "RUR",
"id_offer": 605966498,
"id_prcdoc": 42040,
"id_prcknd": 22215,
"info": {},
"min_order": null,
"sell_by": null,
"value": "10.00"
}
],
"sup_code": "8be655dc-0873-3dfc-994b-602b2e4e0799",
"title": "Избранные для дубля без цены",
"title_low": "избранные для дубля без цены",
"_join_field_name": "doc_type",
"doc_type": {
"name": "supnom",
"parent": "sup-89634082"
}
},
"sort": [
0,
"избранные для дубля без цены"
]
},
{
"_index": "supnoms",
"_type": "doc",
"_id": "supnom-108340974",
"_score": null,
"_routing": "1",
"_source": {
"codes": null,
"folder": null,
"folder_hybrid": null,
"folder_hybrid_type": 0,
"folder_type": null,
"id": "108340974",
"id_supplier": 89634082,
"is_folder": false,
"is_folder_hybrid": null,
"is_linking_disabled": false,
"manufacturer": {
"id": null,
"title": null
},
"market_nom": {
"folder": null,
"id": null
},
"path_market": {
"parents": null,
"pids": null,
"strpath": null
},
"path_supnom": {
"parents": null,
"pids": null,
"strpath": null
},
"prices": [
{
"currency": "RUR",
"id_offer": 605966500,
"id_prcdoc": 42040,
"id_prcknd": 22215,
"info": {},
"min_order": null,
"sell_by": null,
"value": "10.00"
}
],
"sup_code": "867f138d-d8cc-37e7-b1b2-f07a4627ba49",
"title": "Избранные для дубля с ценой",
"title_low": "избранные для дубля с ценой",
"_join_field_name": "doc_type",
"doc_type": {
"name": "supnom",
"parent": "sup-89634082"
}
}
索引中的价格字段如下所示 “价格”: { “类型”:“嵌套”, “特性”: { “货币”: { “类型”:“关键字” }, “id_offer”:{ “类型”:“整数” }, “id_prcdoc”:{ “类型”:“整数” }, “id_prcknd”:{ “类型”:“整数” }, “最低订购”: { “类型”:“关键字” }, “卖者”: { “类型”:“关键字” }, “价值”: { “类型”:“关键字”, “索引”:假 } } }
【问题讨论】:
-
exists 子句是 should 子句 (OR) 的一部分,因此如果文档与任何其他子句匹配,它将被返回。它应该移到外面。
标签: elasticsearch