Filter by Date in Aggregations

I can search for de most popular email, but i want to filter this search for a range of date ex:
(now-30d)-(now) or 1 month.

This is the command:

curl -XGET "http://localhost:9200/_search" -H 'Content-Type: application/json' -d'
{
"query":{
	"range":{
		"data1":{
			"gte" : "now-1d/d",
			"lt" : "now/d"
		}
	}
	"size": 0,
	"aggs": {
		"group_by_state": {
			"terms": {
				"field": "remetente.keyword"
			}
		}
	}
}
}'

and the error:

{"error":{"root_cause":[{"type":"json_parse_exception","reason":"Unexpected character ('\"' 
(code 34)): was expecting comma to separate Object entries\n at [Source: 
org.elasticsearch.transport.netty4.ByteBufStreamInput@1100ac0a; line: 1, column: 
65]"}],"type":"json_parse_exception","reason":"Unexpected character ('\"' (code 34)): was 
expecting comma to separate Object entries\n at [Source: 
org.elasticsearch.transport.netty4.ByteBufStreamInput@1100ac0a; line: 1, column: 
65]"},"status":500}

The fild data1 is a fild type=data, with format=June 12th 2019, 12:45:20.000,
what would it be 12/06/2019 12:45:20.

I just pasted your json in https://jsonformatter.curiousconcept.com/ and it's an incorrect JSON. Missing a comma before "size": 0,.

ok, lack a "," but a error persistis:

New json:

{
"query":{
	"range":{
		"data1":{
			"gte" : "now-1d/d",
			"lt" : "now/d"
		}
	},
	"size": 0,
	"aggs": {
		"group_by_state": {
			"terms": {
				"field": "remetente.keyword"
			}
		}
	}
}
}

and new error:

{"error":{"root_cause":[{"type":"parsing_exception","reason":"[range] malformed query, 
expected [END_OBJECT] but found 
[FIELD_NAME]","line":1,"col":65}],"type":"parsing_exception","reason":"[range] malformed 
query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":65},"status":400}

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