0

I was porting a SQL query on ElasticSearch.

The query needs to substitute an IN clause.

Following this link I implemented the IN this way:

{
  "size": 1,
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "must": [
            {
              "terms": {
                "products.flights.legs.hops.hopFlight.airlineId": [
                  "ib",
                  "lh"
                ]
              }
            }
          ]
        }
      }
    }
  }
}

It is working but probably I have a special case: you see, the hops field in the document is an array, so for a flight with one stop we have two hops.

In that case this query works even when just one of the two hops has ib or lh. It matches a document even when only one of the two hops has one of the airlines and the other hop is a different airline, not include in my terms.

I actually want to return only documents that, as airlineId, have only ib or lh or a combination of both.

Is it possible to do it on ElasticSearch?

dierre
  • 7,140
  • 12
  • 75
  • 120
  • 1
    Looks like you need nested documents - https://www.elastic.co/guide/en/elasticsearch/reference/6.2/nested.html#_using_literal_nested_literal_fields_for_arrays_of_objects – Nirmal Apr 17 '18 at 19:38
  • I will look into it, thank you. – dierre Apr 17 '18 at 20:05

0 Answers0