Can't search on date field

Hello. New elasticsearch user here. I'm sure you will be seeing many more
posts from me as I muddle my way along on the way to a solid understanding
of the product. Mostly I've just been lurking the forums, trying to piece
together different pieces of information. Currently I'm playing around in a
sandbox environment, trying to learn about indexing and mapping and sharding
and everything else that there is to learn about, and trying not to get
overwhelmed in the process by how much there actually is to learn. Anyway,
on to my first question...

So I have an index that has a field called post_date that is a date field.
From the index mapping...

post_date: {
format: dateOptionalTime
type: date
}

So I have a bunch of documents with dates in the standard date format, e.g.
"2012-07-15T14:12:12", and I was trying to search on documents in a certain
date range. I have used many variations of queries that I got from reading
the documentation and forum posts but none of them seem to be working. By
that I mean that when I search the index on the date range, the number of
hits that I get back are the total number of documents in the index, so it
doesn't seem to be applying my filter.

So here is the final query that I ended up with:

{
"query": {
"constant_score": {
"filter": {
"numeric_range": {
"post_date": {
"lt": "2012-07-16",
"gte": "2012-07-01"
}
}
}
}
}
}

I know from the data in the index that there are dates both in this range
and not in this range, so I would expect to have it return only the dates in
that range. However, as I said, it's returning everything.

So does anyone have an idea about why this isn't working and ultimately how
I can write the query so that it does what I would expect?

Many thanks in advance.

--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/Can-t-search-on-date-field-tp4021882.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.

--

Hi Mary

So I have an index that has a field called post_date that is a date field.
From the index mapping...

post_date: {
format: dateOptionalTime
type: date
}

By that I mean that when I search the index on the date range, the number of
hits that I get back are the total number of documents in the index, so it
doesn't seem to be applying my filter.

By the looks of what you've posted, your query should work, which
probably means that you're doing something else wrong that you haven't
mentioned so far.

I suggest gisting a complete curl recreation (including index creation,
indexing a few docs, and the query) which will help us see the issue.

ta

clint

--