Date rage query


(Aniket) #1

I am trying to execute query on elastic search which should give me results within perticuler date range. Mapping is as follows.

    {
      "customertransaction" : {
        "mappings" : {
          "doc" : {
            "properties" : {
            
              "DTCREATED" : {
                "type" : "date",
                "format" : "dateOptionalTime"
              },
                "STATUS" : {
                "type" : "string"
              },
}

I have written following query for it

SearchRequest requestQuery =
  Requests.searchRequest(ConstantsValue.indexName)
.types(ConstantsValue._Type)
.source("{size:999999,"
	+ "\"_source\" : "
	+ "[\"DTCREATED\", \"STATUS\"]"
	+ ",\"aggs\": "
	+ "{\"group_by_STATUS\": {\"terms\": {\"field\": \"STATUS\"},"
	+ "\"aggs\" : "
	+ "{\"group_by_DATE\" : {\"date_histogram\" : "
	+ "{\"field\" : \"DTCREATED\", \"interval\" : \"day\","
	+ "\"format\" : \"yyyy-MM-dd\" },"
	+ "\"aggs\" : "
	+ "{\"grades_count\" : { \"value_count\" : { \"field\" : \"STATUS\" } }}}}}}}");

DTCREATED field contains both date and time. I expect status count daily for from date and to date range. How can I add date range filter in this query.


(Isabel Drost-Fromm) #2

Without looking at the query in detail: This looks like you are trying to directly implement the Query through the Java API. What I personally find a better route when searching the right query syntax is to go and use the Elasticsearch REST API first, e.g. through Sense/Console in Kibana and only move to Java after that. That way you'll be able to iterate much faster.


(system) #3

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