gpt4 book ai didi

elasticsearch - ElasticSearch术语查询与query_string?

转载 作者:行者123 更新时间:2023-12-02 23:00:33 29 4
gpt4 key购买 nike

当我用query_string查询索引时,我得到的结果

{
"query": {
"bool": {
"must": [ ],
"must_not": [ ],
"should": [
{
"query_string": {
"default_field": "Printer.Name",
"query": "HL-2230"
}
}
]
}
},
"from": 0,
"size": 10,
"sort": [ ],
"aggs": { }
}

但是当我使用术语查询进行查询时,没有任何结果
{
"query": {
"bool": {
"must": [ ],
"must_not": [ ],
"should": [
{
"term": {
"Printer.Name": "HL-2230"
}
}
]
}
},
"from": 0,
"size": 10,
"sort": [ ],
"aggs": { }
}

我知道未对术语进行分析并已对query_string进行了分析,但名称已为“HL-2230”,为什么它与术语查询不匹配?我也尝试过搜索“hl-2230”,但仍然没有得到任何结果。

enter image description here

编辑:映射如下所示。打印机是产品的子级。不知道这是否有所作为
    {
"state": "open",
"settings": {
"index": {
"creation_date": "1453816191454",
"number_of_shards": "5",
"number_of_replicas": "1",
"version": {
"created": "1070199"
},
"uuid": "TfMJ4M0wQDedYSQuBz5BjQ"
}
},
"mappings": {
"Product": {
"properties": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"ProductName": {
"type": "nested",
"properties": {
"Name": {
"store": true,
"type": "string"
}
}
},
"ProductCode": {
"type": "string"
},
"Number": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"id": {
"index": "no",
"store": true,
"type": "integer"
},
"ShortDescription": {
"store": true,
"type": "string"
},
"Printer": {
"_routing": {
"required": true
},
"_parent": {
"type": "Product"
},
"properties": {
"properties": {
"RelativeUrl": {
"index": "no",
"store": true,
"type": "string"
}
}
},
"PrinterId": {
"index": "no",
"store": true,
"type": "integer"
},
"Name": {
"store": true,
"type": "string"
}
}
},
"aliases": [ ]
}
}

最佳答案

根据您上面提供的映射

"Name": {
"store": true,
"type": "string"
}
Name被分析。因此 HL-2230将分为两个 token HL2230。这就是 term query不起作用而 query_string起作用的原因。当您使用 term query时,它将搜索不存在的确切术语 HL-2230

关于elasticsearch - ElasticSearch术语查询与query_string?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35224042/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com