gpt4 book ai didi

elasticsearch - ElasticSearch:关键字查询不起作用

转载 作者:行者123 更新时间:2023-12-02 22:29:40 24 4
gpt4 key购买 nike

我有关键字查询问题。

我想按键和值过滤categoryProperties。

键是“颜色”,值包含“mavi”

但这给了我文档,其中包含键为“color”,值包含“Beyaz”

你知道为什么吗

要求
我在下面查询searchQuery.categoryProperties.key和searchQuery.categoryProperties.values.value。

{
"query": {
"bool": {
"must": [{
"nested": {
"query": {
"bool": {
"must": [{
"nested": {
"query": {
"bool": {
"should": [{
"bool": {
"must_not": [{
"term": {
"searchQuery.categoryProperties.key": {
"value": "color"
}
}
}]
}
},
{
"bool": {
"must": [{
"term": {
"searchQuery.categoryProperties.key": {
"value": "color"
}
}
},
{
"nested": {
"query": {
"term": {
"searchQuery.categoryProperties.values.value": {
"value": "Mavi"
}
}
},
"path": "searchQuery.categoryProperties.values"
}
}]
}
}]
}
},
"path": "searchQuery.categoryProperties"
}
}]
}
},
"path": "searchQuery"
}
}]
}
}
}

这是我的
响应
{
"hits": {
"total": 1,
"max_score": null,
"hits": [{
"_index": "favoritesearchsearchmodelindex_2",
"_type": "favoritesearchsearchmodel",
"_id": "76175",
"_score": null,
"_source": {
"searchQuery": {
"categoryProperties": [
{
"key": "color",
"values": [{
"value": "Beyaz"
}]
}]
}
}
}]
}
}

以及我的文档的映射:
映射
{
"favoritesearchsearchmodelindex_2": {
"mappings": {
"favoritesearchsearchmodel": {
"properties": {
"searchQuery": {
"type": "nested",
"properties": {
"categoryProperties": {
"type": "nested",
"properties": {
"intValue": {
"type": "integer"
},
"key": {
"type": "keyword"
},
"values": {
"type": "nested",
"properties": {
"value": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
}
}
}

最佳答案

我解决了我的问题。您可以查看真正的答案:Elastic Discuss Forum

根据Mark的回应,我更改了映射。
新映射

{
"favoritesearchsearchmodelindex_2": {
"mappings": {
"favoritesearchsearchmodel": {
"properties": {
"searchQuery": {
"type": "nested",
"properties": {
"categoryProperties": {
"properties": {
"key": {
"type": "keyword"
},
"numberValue": {
"type": "double"
},
"values": {
"properties": {
"value": {
"type": "keyword"
}
}
}
}
},
"keyList": {
"properties": {
"value": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
}

更改映射后,我意识到;
我正在搜索 searchQuery.categoryProperties.key不是 color。我有一个数组,如果键之一不是 color,则可以搜索,但不适合我。
我创建了一个 keyList数组,并将 searchQuery.categoryProperties.key的所有分组键放入 keyList对象。
现在,我首先搜索 keyList。它给了我正确的答案。这解决了我的问题。

这是正确的REQUEST
{
"query": {
"bool": {
"must": [{
"nested": {
"query": {
"bool": {
"filter": [{
"bool": {
"should": [{
"bool": {
"must_not": [{
"term": {
"searchQuery.keyList.value": {
"value": "color"
}
}
}]
}
},
{
"bool": {
"must": [{
"term": {
"searchQuery.categoryProperties.key": {
"value": "color"
}
}
},
{
"term": {
"searchQuery.categoryProperties.values.value": {
"value": "Mavi"
}
}
}]
}
}]
}
}]
}
},
"path": "searchQuery"
}
}]
}
}
}

关于elasticsearch - ElasticSearch:关键字查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46404592/

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