I would like to create an Elasticsearch query that matches "sup_code": "X4595093". The original query is
{
"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
}
When I run this query I get the following response:
{
"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"
]
}
]
}
}
Now I would like to specify a query that matches "sup_code": "X4595093". Query looks like this:
{
"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
}
I get zero hits with this query. Could someone explain to me what am I missing? Sup_code is a text field, not a nested one.
Since Sup_code is a text field, you can try like this
"supplier_nom.sup_code.keyword": ["X4754995"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.