Unable to get gte and lte from elastic Java API in range query

As far as I can see there are a couple of issues here:

  • The value in the query is not in the interval specified for the example document.
  • If you are looking for a range that covers the IP in the query I think you may have mixed up the lte and gte clauses and should flip them.
[quote="AKASH_DUBEY1, post:20, topic:257781"]
```
{
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "ipFromLong": {
              "from": 28147177551,
              "to": null,
              "include_lower": true,
              "include_upper": false,
              "boost": 1
            }
          }
        },
        {
          "range": {
            "ipToLong": {
              "from": null,
              "to": 28147177551,
              "include_lower": false,
              "include_upper": true,
              "boost": 1
            }
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  }
}
```
[/quote]

In given query I tried all possible combination already nathing worked and ipToLong and ipForLong are just long variable then what do u mean by intervals here and again I tried all combination include_lower and include_upper .one more thing ,putting my point again If you run this clauses of range in two different bool queries this works and I menton again both are different fields if you run in single then doesn't so fliping should have no mean with it.

I tried the following example based on what you wrote. That's the typical script which could help. So please, next time, provide such a script. It's easy to read and understand what you are doing.

DELETE test 
PUT test
{
  "mappings": {
    "properties": {
      "ipFromLong": {
        "type": "long"
      },
      "ipToLong": {
        "type": "long"
      }
    }
  }
}
POST test/_doc
{
  "ipToLong": 28147177550,
  "ipFromLong": 28147177543
}

From that example, we can test your subqueries:

GET test/_search
{
  "query": {
    "range": {
      "ipToLong": {
        "to": 28147177551
      }
    }
  }
}

This one gives the hit. Why this? Because for ipToLong: 28147177550 < 28147177551

But:

GET test/_search
{
  "query": {
    "range": {
      "ipFromLong": {
        "from": 28147177551
      }
    }
  }
}

This one gives no hit. Why this? Because for ipFromLong 28147177543 < 28147177551. So it can't match.

That's why your query can not match anything.

I'm now trying to understand what exactly you want to do actually.
And I wonder if you are trying to find values in intervals. In which case, I'd highly recommend using:

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