0

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?

1 Answer 1

1

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"
              }
            }
          }
        }
      ]
    }
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Hallelujah! Thanks! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.