Range-Query not working l

Hello,

I use:

Configurated search query:

array(2) {
  ["index"]=>
  string(19) "my_index_*"
  ["body"]=>
  array(4) {
    ["query"]=>
    array(1) {
      ["range"]=>
      array(1) {
        ["data.main.startDateTime"]=>
        array(2) {
          ["lte"]=>
          string(25) "2008-08-23T23:05:10"
          ["gte"]=>
          string(25) "2008-08-23T23:05:08+02:00"
        }
      }
    }
    ["sort"]=>
    array(1) {
      [0]=>
      array(1) {
        ["data.main.startDateTime"]=>
        array(1) {
          ["order"]=>
          string(4) "desc"
        }
      }
    }
    ["from"]=>
    int(0)
    ["size"]=>
    int(100)
  }
}

Calling the search-Request (Elasticsearch\Client->search($params) with the parameters above returns also records out of the range. Seems the range are ignored....

Expected 2 hits
Actual more than 10 hits

As example the query returns this record, which is out of the range

// the record
{
	"_index": "my_index_200808",
	"_type": "_doc",
	...
	"_version": 1,
	"_seq_no": 34,
	"_primary_term": 1,
	"found": true,
	"_source": {
		...,
		"data": {
			"main": {
				...
				"startDateTime": "2008-08-23T23:25:22+02:00",
				...
			},
			...
		}
	}
}

What is wrong with the query configuration? How to use the range query?

You shall try

GET /_search
{
"query":
    {
    "bool":
        {
            "must": [
                  "range":
                   {
                       "startDateTime": { "gte": "now-1d", "lte": "now"
                   }
             ]
        }
    }
}

This shall give you day between last and until this time, since we have used now-1d to now. Try changing the time range in query.

Cheers!

You have specified timezone in only one of your conditions so you may be searching a window larger than you think.

@ErSumit @Christian_Dahlqvist thx for response,

the query configuration was wrong, witn the fix it works:

array(2) {
  ["index"]=>
  string(19) "my_index_*"
  ["body"]=>
  array(4) {
    ["query"]=>
    array(1) {
      ["range"]=>
      array(1) {
        ["data.main.startDateTime"]=>
        array(2) {
          ["lte"]=>
          string(25) "2008-08-23T23:05:10+02:00"
          ["gte"]=>
          string(25) "2008-08-23T23:05:08+02:00"
        }
      }
    }
    ["sort"]=>
    array(1) {
      [0]=>
      array(1) {
        ["data.main.startDateTime"]=>
        array(1) {
          ["order"]=>
          string(4) "desc"
        }
      }
    }
    ["from"]=>
    int(0)
    ["size"]=>
    int(100)
  }
}
Elasticsearch\Client:1212

Thanks and bye

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