使用嵌套查询时弹性搜索问题(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" } } } } ] } } }使用嵌套查询时弹性搜索问题(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" } } } } ] } } }