Query DSL: How to use must in should condition?

I need to do a time period-period match like this:

Data has 2 time field such as d_from and d_to.
Now given param p_from and param p_to.

I need to get records which SHOULD satisfy following conditions:

  1. p_from gte d_from and(MUST) p_from lte d_to
  2. p_to gte d_from and(MUST) p_to lte d_to
  3. p_from <= d_from and(MUST) p_to >= d_to

1 and 2 is easy to do it seems just use bool-should-range is ok, but condition 3 makes me confused, it need two params satisfy their own condition by MUST then SHOULD with 1 and 2...

Can somebody help me please? Thanks alot..

emm... Maybe I found solution...Well, I use php so here's an array...

-queryField: array:1 [
    "bool" => array:1 [
      "should" => array:3 [
        0 => array:1 [
          "range" => array:1 [
            "SESSION_START_TIME" => array:2 [
              "gte" => "2017-11-24T16:20:44+08:00"
              "lte" => "2017-11-24T16:25:44+08:00"
            ]
          ]
        ]
        1 => array:1 [
          "range" => array:1 [
            "SESSION_END_TIME" => array:2 [
              "gte" => "2017-11-24T16:20:44+08:00"
              "lte" => "2017-11-24T16:25:44+08:00"
            ]
          ]
        ]
        2 => array:1 [
          "bool" => array:1 [
            "must" => array:2 [
              0 => array:1 [
                "range" => array:1 [
                  "SESSION_START_TIME" => array:1 [
                    "lt" => "2017-11-24T16:20:44+08:00"
                  ]
                ]
              ]
              1 => array:1 [
                "range" => array:1 [
                  "SESSION_END_TIME" => array:1 [
                    "gt" => "2017-11-24T16:25:44+08:00"
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ]

well I found this solution will contain more records.. it is not precise...anybody have idea?

Finally I solve this by NLPchina/elasticsearch-sql...
see

Great project!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.