0

I store in Elasticsearc objects like that:

{
  "userName": "Cool User",
  "orders":[
    {
      "orderType": "type1",
      "amount": 500
    },
    {
      "orderType": "type2",
      "amount": 1000
    }
  ]
}

And all is ok while I`m searching by 'orders.orderType' or 'orders.amount' fields. But what query I have to use for getting objects, which has 'orders.amount >= 500' and 'orders.orderType=type2'?

I`ve tried to query like that:

{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "orders.amount": {
              "from": "499"
            }
          }
        },
        {
          "query_string": {
            "query": "type2",
            "fields": [
              "orders.orderType"
            ]        
          }
        }
      ]
    }
  }
}

..but this request returns records that has 'orders.orderType=type2' OR 'orders.amount >= 500'.

Please help me to construct query, that will look for objects that has object inside orders array and it object has to have amount >= 500 AND 'orderType=type2'.

dsgr
  • 99
  • 6

1 Answers1

0

Finally, I found blog post that describes exactly my case. https://www.bmc.com/blogs/elasticsearch-nested-searches-embedded-documents/ Thanks for help.

dsgr
  • 99
  • 6
  • Kindly add context to any links so your answer is self contained, meaning the answer needs to be here in the Answer itself. See ["Provide context for links"](https://stackoverflow.com/help/how-to-answer). How did you solve your issue? – Scratte Oct 01 '20 at 20:08