[英]Multilevel Terms Query Elasticsearch
我想創建一個與“sup_code”匹配的 Elasticsearch 查詢:“X4595093”。 原始查詢是
{
"query": {
"bool": {
"must": [
{
"has_parent": {
"parent_type": "doc",
"query": {
"bool": {
"must": [
{
"terms": {
"id": [
33172
]
}
},
{
"range": {
"created": {
"lte": "now/d"
}
}
},
{
"range": {
"expires": {
"gte": "now/d"
}
}
}
]
}
}
}
},
{
"term": {
"doc_type": "item"
}
},
{
"bool": {
"should": [
{
"term": {
"have_prices": true
}
},
{
"term": {
"is_folder": true
}
}
]
}
},
{
"term": {
"id": 254702776
}
}
],
"must_not": {
"exists": {
"field": "folder"
}
}
}
},
"sort": [
{
"is_folder": {
"order": "desc"
}
},
{
"title_low.order": {
"order": "asc"
}
}
],
"size": 1000
}
當我運行此查詢時,我得到以下響應:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": null,
"hits": [
{
"_index": "prices",
"_type": "doc",
"_id": "item-254702776",
"_score": null,
"_routing": "1",
"_source": {
"id": 254702776,
"id_pricedoc": 33172,
"path": null,
"supplier": {
"id": 89587333,
"type": "online"
},
"title": "00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123",
"is_folder": false,
"prices": [
{
"value": "По запросу",
"id_prcknd": 6622,
"currency": "RUR",
"id_offer": 604818674
},
{
"value": "По запросу",
"id_prcknd": 6622,
"currency": "RUR",
"id_offer": 604915992
}
],
"market": {
"title": null,
"uuid": null,
"folder": null,
"path": null
},
"have_prices": true,
"folder": null,
"_join_field_name": "doc_type",
"pricedoc_created": "2019-06-19",
"supplier_nom": {
"manufacturer": {
"title": null,
"id": null
},
"id": 107549048,
"codes": null,
"market_nom": {
"id": null
},
"sup_code": "X4595093"
},
"doc_type": {
"parent": "doc-33172",
"name": "item"
},
"title_low": "00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123"
},
"sort": [
0,
"00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123 00012123"
]
}
]
}
}
現在我想指定一個匹配“sup_code”的查詢:“X4595093”。 查詢如下所示:
{
"query": {
"bool": {
"must": [
{
"has_parent": {
"parent_type": "doc",
"query": {
"bool": {
"must": [
{
"terms": {
"id": [
33172
]
}
},
{
"range": {
"created": {
"lte": "now/d"
}
}
},
{
"range": {
"expires": {
"gte": "now/d"
}
}
}
]
}
}
}
},
{
"term": {
"doc_type": "item"
}
},
{
"bool": {
"should": [
{
"term": {
"have_prices": true
}
},
{
"term": {
"is_folder": true
}
}
]
}
},
{
"terms": {
"supplier_nom.sup_code": ["X4754995"]
}
}
],
"must_not": {
"exists": {
"field": "folder"
}
}
}
},
"sort": [
{
"is_folder": {
"order": "desc"
}
},
{
"title_low.order": {
"order": "asc"
}
}
],
"size": 1000
}
這個查詢我得到零命中。 有人可以向我解釋我錯過了什么嗎? Sup_code 是一個文本字段,而不是嵌套的。
由於 Sup_code 是一個文本字段,你可以這樣嘗試
"supplier_nom.sup_code.keyword": ["X4754995"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.