gpt4 book ai didi

querydsl - Elasticsearch 多个字段的数组

转载 作者:行者123 更新时间:2023-12-03 02:02:09 30 4
gpt4 key购买 nike

我有以下形式的数据

{
"Name": "Bolognaise, tomato, olive and feta tart"
"Prep Time": 20,
"Cook Time": 25,
"Servings": 4,
"Ingredients": [
{
"name": "puff pastry",
"id": 17,
"weight": 100
},
{ "name": "bolognaise",
"id": 18,
"weight": 150
},
{
"name": "tomatoes",
"id": 19,
"weight": 200
},
{
"name": "olives",
"id": 20,
"weight": 300
},
{
"name": "cheese",
"id": 21,
"weight": 230
},
{
"name": "baby rocket",
"id": 22,
"weight": 400
}
],
"Views": 0,
"Urls": "xcd.com",
"Tags": [
"Tomato",
"Lunch"
],
"Main_ingredient": {
"type": "Tomato",
"id": 101,
"weight": 500
}
}
},

我正在使用此查询
 {
"query": {
"bool": {
"must": [
{ "match": { "Main_ingredient.type": "Tomato" }},
{"range":{"Main_ingredient.weight":{"lte":1000}}},
{
"nested": {
"path": "Ingredients",
"query": {
"bool": {
"must": [
{ "match": { "Ingredients.name": "cheese" }},
{ "range": { "Ingredients.weight":{"lte":400} }},
{ "match": { "Ingredients.name": "olives" }},
{ "range": { "Ingredients.weight":{"lte":400} }}
]
}}}}
]
}}}

我想更改查询,以便如果我通过重量和主要成分,那么它应该返回给我具有相同主要成分的ID,并且该主要成分的重量小于通过的重量。现在它返回null

最佳答案

因此,如果我正确理解您的问题,那么您正在寻找Main_ingredients.type上的term match和重量上的less than range。然后将这些“与”过滤器设为多个。由于您具有一个分析Main_ingredient.type字段和Ingredients.name字段的映射,因此您必须提供这些字符串的小写值。最好只更改映射以不分析那些字段。我认为您正在寻找类似下面的内容。显然,您将想要添加任何其他“和”过滤器过滤块,以添加要匹配的其他成分。

GET rec/_search
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"and": {
"filters": [
{
"term": {
"main_ingredient.type": "tomato"
}
},
{
"range": {
"main_ingredient.weight": {
"lt": 1000
}
}
}
]
}
},
{
"and": {
"filters": [
{
"term": {
"ingredients.name": "tomatoes"
}
},
{
"range": {
"ingredients.weight": {
"lt": 300
}
}
}
]
}
}
],
"_cache": true
}
}
}
}
}

关于querydsl - Elasticsearch 多个字段的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31242030/

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