简体   繁体   English

多级术语查询 Elasticsearch

[英]Multilevel Terms Query Elasticsearch

I would like to create an Elasticsearch query that matches "sup_code": "X4595093".我想创建一个与“sup_code”匹配的 Elasticsearch 查询:“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".现在我想指定一个匹配“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. Sup_code 是一个文本字段,而不是嵌套的。

Since Sup_code is a text field, you can try like this由于 Sup_code 是一个文本字段,你可以这样尝试

"supplier_nom.sup_code.keyword": ["X4754995"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM