使用嵌套查询时弹性搜索问题(Issue with elastic search when using nested query)

编程入门 行业动态 更新时间:2024-10-11 01:18:35
使用嵌套查询时弹性搜索问题(Issue with elastic search when using nested query)

我有以下查询:

{ "from": 0, "size": 20, "sort": { "prices_count": "desc" }, "query": { "bool": { "must": [{ "terms": { "category_ids": ["3"] } }, { "terms": { "manufacturer_id": ["5"] } }, { "range": { "prices_count": { "gte": 1 } } }] }, "nested": { "bool": { "must": [{ "match": { "specs.model": "iphone-6s" } }] } } } }

我收到以下错误:

Fatal error: Uncaught exception 'Elastica\Exception\ResponseException' with message 'failed to parse search source. expected field name but got [START_OBJECT]' in

如果我只在查询中保留nested部分,它将按预期工作。

是不是可以在同一个请求中使用'普通'和嵌套查询,或者我只是做错了?

I have following query:

{ "from": 0, "size": 20, "sort": { "prices_count": "desc" }, "query": { "bool": { "must": [{ "terms": { "category_ids": ["3"] } }, { "terms": { "manufacturer_id": ["5"] } }, { "range": { "prices_count": { "gte": 1 } } }] }, "nested": { "bool": { "must": [{ "match": { "specs.model": "iphone-6s" } }] } } } }

I get the following error:

Fatal error: Uncaught exception 'Elastica\Exception\ResponseException' with message 'failed to parse search source. expected field name but got [START_OBJECT]' in

If i leave just the nested part in the query, it works as expected.

Is it not possible to have and 'ordinary' and nested query in the same request, or am I just doing it wrong?

最满意答案

你需要像这样写:

{ "from": 0, "size": 20, "sort": { "prices_count": "desc" }, "query": { "bool": { "must": [ { "terms": { "category_ids": [ "3" ] } }, { "terms": { "manufacturer_id": [ "5" ] } }, { "range": { "prices_count": { "gte": 1 } } }, { "nested": { "path": "specs", "query": { "match": { "specs.model": "iphone-6s" } } } } ] } } }

You need to write it like this:

{ "from": 0, "size": 20, "sort": { "prices_count": "desc" }, "query": { "bool": { "must": [ { "terms": { "category_ids": [ "3" ] } }, { "terms": { "manufacturer_id": [ "5" ] } }, { "range": { "prices_count": { "gte": 1 } } }, { "nested": { "path": "specs", "query": { "match": { "specs.model": "iphone-6s" } } } } ] } } }

更多推荐

本文发布于:2023-08-07 16:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465332.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   弹性   Issue   elastic   nested

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!