gpt4 book ai didi

elasticsearch - 格式错误的查询,预期 [END_OBJECT] 但找到 [FIELD_NAME]

转载 作者:行者123 更新时间:2023-12-02 22:21:41 26 4
gpt4 key购买 nike

原始查询看起来像这样

{
"query": {
"bool": {
"must": [
{
"has_parent": {
"parent_type": "doc",
"query": {
"bool": {
"must": [
{
"terms": {
"id": [
713
]
}
},
{
"range": {
"created": {
"lte": "now/d"
}
}
},
{
"range": {
"expires": {
"gte": "now/d"
}
}
}
]
}
}
}
},
{
"term": {
"doc_type": "item"
}
},
{
"bool": {
"should": [
{
"term": {
"have_prices": true
}
},
{
"term": {
"is_folder": true
}
}
]
}
}
],
"must_not": {
"exists": {
"field": "folder"
}
}
}
},
"sort": [
{
"is_folder": {
"order": "desc"
}
},
{
"title_low.order": {
"order": "asc"
}
}
],
"size": 1000
}

我得到了一些结果

"hits": {
"total": 19,
"max_score": null,
"hits": [
{
"_index": "prices",
"_type": "doc",
"_id": "item-6800004",
"_score": null,
"_routing": "1",
"_source": {
"id": 6800004,
"id_pricedoc": 713,
"title": "\"водка №1\" 1",
"title_low": "\"водка №1\" 1",
"supplier": {
"id": 7831,
"type": null
},
"supplier_nom": {
"id": 1375697,
"market_nom": {
"id": null
},
"codes": null,
"sup_code": "7a6713a5-73c1-3acb-9b62-9e38b2314dce",
"manufacturer": {
"id": null,
"title": null
}
},
"is_folder": false,
"folder": null,
"path": null,
"pricedoc_created": "2016-03-21",
"prices": [
{
"currency": "RUR",
"id_offer": 15735967,
"id_prcknd": 167,
"value": "391.50"
}
],
"have_prices": true,
"market": {
"title": null,
"uuid": null,
"folder": null,
"path": null
},
"_join_field_name": "doc_type",
"doc_type": {
"name": "item",
"parent": "doc-713"
}
},
"sort": [
0,
"\"водка №1\" 1"
]
}

现在我也想得到结果 where "id_prcknd": 167

修改后的查询看起来像这样

{
"query": {
"bool": {
"must": [
{
"has_parent": {
"parent_type": "doc",
"query": {
"bool": {
"must": [
{
"terms": {
"id": [
713
]
}
},
{
"range": {
"created": {
"lte": "now/d"
}
}
},
{
"range": {
"expires": {
"gte": "now/d"
}
}
}
]
}
}
}
},
{
"term": {
"doc_type": "item"
}
},
{
"bool": {
"should": [
{
"term": {
"have_prices": true
}
},
{
"term": {
"is_folder": true
}
}
]
}
}
],
"must_not": {
"exists": {
"field": "folder"
}
}
},
"nested": {
"path": "prices",
"query": {
"bool": {
"must": [
{
"match": {
"prices.id_prcknd": 167
}
}
]
}
}
},
"sort": [
{
"is_folder": {
"order": "desc"
}
},
{
"title_low.order": {
"order": "asc"
}
}
],
"size": 1000
}}

但我收到错误 Elasticsearch malformed query, expected [END_OBJECT] but found [FIELD_NAME]我哪里错了?我想匹配“id_prcknd”的对象:167stackoverflow 说我发布的主要是代码,但这是因为 Elasticsearch 中的大量查询。

最佳答案

Elasticsearch 试图表达的意思是,它不希望看到其他键,而是 bool。在字典中("query" 下的值)。

在您的示例代码中,您有这样的内容:

{
"query": {
"bool": {
"must": [
{...},
{...},
{...}
],
"must_not": {...},
"nested": {...}, // this should go under "must"
"sort": [...], // this should go on the same level as "query"
"size": 1000 // this should go on the same level as "query"
}
}

"bool"这里指的是 bool 查询,并且应该是字典中的唯一键。

你应该做的是移动"nested"进入它自己的字典和 must 的第四个元素数组(如果我理解你想要正确实现的逻辑)。另请注意 "sort""size"应该移动 - 这次,移动到与 "query" 相同的级别.

完整的查询如下所示:

{
"query": {
"bool": {
"must": [
{
"has_parent": {
"parent_type": "doc",
"query": {
"bool": {
"must": [
{
"terms": {
"id": [
713
]
}
},
{
"range": {
"created": {
"lte": "now/d"
}
}
},
{
"range": {
"expires": {
"gte": "now/d"
}
}
}
]
}
}
}
},
{
"term": {
"doc_type": "item"
}
},
{
"bool": {
"should": [
{
"term": {
"have_prices": true
}
},
{
"term": {
"is_folder": true
}
}
]
}
},
{
"nested": {
"path": "prices",
"query": {
"bool": {
"must": [
{
"match": {
"prices.id_prcknd": 167
}
}
]
}
}
}
}
],
"must_not": {
"exists": {
"field": "folder"
}
}
}
},
"sort": [
{
"is_folder": {
"order": "desc"
}
},
{
"title_low.order": {
"order": "asc"
}
}
],
"size": 1000
}

关于elasticsearch - 格式错误的查询,预期 [END_OBJECT] 但找到 [FIELD_NAME],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58644067/

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