making date field work

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

making date field work

mfeingold
Is there a trick to making date field work? I tried a few things to no
avail here is what I tried:

1. I mapped the field specifying field type as "date" - no explicit
definition for analyzer. I indexed a few records with the date
formatted as yyyy-mm-dd and I tried to run both term and text queries
providing date in the same format. Again without explicitly specifying
the analyzer. Both queries came back empty even though when I pulled
the documents using queries based on different fields I can see the
date is there
2. I did pretty much the same but changed the field type to "string"
with the same result.

What am I missing here?
Reply | Threaded
Open this post in threaded view
|

Re: making date field work

avasilenko
There was a fix in 0.17.6 - https://github.com/elasticsearch/elasticsearch/issues?labels=v0.17.6&sort=created&direction=desc&state=closed&page=1 . Please specify the version, you're using.
Alexandr Vasilenko

2011/8/20 Michael Feingold <[hidden email]>
Is there a trick to making date field work? I tried a few things to no
avail here is what I tried:

1. I mapped the field specifying field type as "date" - no explicit
definition for analyzer. I indexed a few records with the date
formatted as yyyy-mm-dd and I tried to run both term and text queries
providing date in the same format. Again without explicitly specifying
the analyzer. Both queries came back empty even though when I pulled
the documents using queries based on different fields I can see the
date is there
2. I did pretty much the same but changed the field type to "string"
with the same result.

What am I missing here?

Reply | Threaded
Open this post in threaded view
|

Re: making date field work

mfeingold
I am currently on 0.17.2. Which one should I be using?

On Aug 22, 2:03 am, Alex Vasilenko <[hidden email]> wrote:

> There was a fix in 0.17.6 -https://github.com/elasticsearch/elasticsearch/issues?labels=v0.17.6&...
> .
> Please specify the version, you're using.
> Alexandr Vasilenko
>
> 2011/8/20 Michael Feingold <[hidden email]>
>
> > Is there a trick to making date field work? I tried a few things to no
> > avail here is what I tried:
>
> > 1. I mapped the field specifying field type as "date" - no explicit
> > definition for analyzer. I indexed a few records with the date
> > formatted as yyyy-mm-dd and I tried to run both term and text queries
> > providing date in the same format. Again without explicitly specifying
> > the analyzer. Both queries came back empty even though when I pulled
> > the documents using queries based on different fields I can see the
> > date is there
> > 2. I did pretty much the same but changed the field type to "string"
> > with the same result.
>
> > What am I missing here?
Reply | Threaded
Open this post in threaded view
|

Re: making date field work

kimchy
Administrator
The format that you use is not affected by the mentioned problem (but, you should upgrade in any case to latest). Back to your question, can you post a simpel recreation of what does not work? If you index a field with the yyyy-MM-dd format, it will automatically be detected as date type, so you don't even need to explicitly specify it as date. Also, when working with dates, there isn't really a meaning for an analyzer.

On Mon, Aug 22, 2011 at 6:43 PM, Michael Feingold <[hidden email]> wrote:
I am currently on 0.17.2. Which one should I be using?

On Aug 22, 2:03 am, Alex Vasilenko <[hidden email]> wrote:
> There was a fix in 0.17.6 -https://github.com/elasticsearch/elasticsearch/issues?labels=v0.17.6&...
> .
> Please specify the version, you're using.
> Alexandr Vasilenko
>
> 2011/8/20 Michael Feingold <[hidden email]>
>
> > Is there a trick to making date field work? I tried a few things to no
> > avail here is what I tried:
>
> > 1. I mapped the field specifying field type as "date" - no explicit
> > definition for analyzer. I indexed a few records with the date
> > formatted as yyyy-mm-dd and I tried to run both term and text queries
> > providing date in the same format. Again without explicitly specifying
> > the analyzer. Both queries came back empty even though when I pulled
> > the documents using queries based on different fields I can see the
> > date is there
> > 2. I did pretty much the same but changed the field type to "string"
> > with the same result.
>
> > What am I missing here?

Reply | Threaded
Open this post in threaded view
|

Re: making date field work

mfeingold
Well, it is embarrassing. After several days of on and off poking
around, I figured it out. It turns out that if the case of the field
name you use in both mapping and query does not match the case of the
"same" name in the json with the data, the "mapped" field stays empty
and searches against it come back empty too.

Lesson learned. But to make it easier on other people - would it make
sense to introduce a way to make upload "strict" - meaning that all
fields in the data json have to be mapped upfront. That's the mode I
would use and it would definitely save me some grief.

On Aug 22, 1:50 pm, Shay Banon <[hidden email]> wrote:

> The format that you use is not affected by the mentioned problem (but, you
> should upgrade in any case to latest). Back to your question, can you post a
> simpel recreation of what does not work? If you index a field
> with the yyyy-MM-dd format, it will automatically be detected as date type,
> so you don't even need to explicitly specify it as date. Also, when working
> with dates, there isn't really a meaning for an analyzer.
>
> On Mon, Aug 22, 2011 at 6:43 PM, Michael Feingold <[hidden email]>wrote:
>
> > I am currently on 0.17.2. Which one should I be using?
>
> > On Aug 22, 2:03 am, Alex Vasilenko <[hidden email]> wrote:
> > > There was a fix in 0.17.6 -
> >https://github.com/elasticsearch/elasticsearch/issues?labels=v0.17.6&...
> > > .
> > > Please specify the version, you're using.
> > > Alexandr Vasilenko
>
> > > 2011/8/20 Michael Feingold <[hidden email]>
>
> > > > Is there a trick to making date field work? I tried a few things to no
> > > > avail here is what I tried:
>
> > > > 1. I mapped the field specifying field type as "date" - no explicit
> > > > definition for analyzer. I indexed a few records with the date
> > > > formatted as yyyy-mm-dd and I tried to run both term and text queries
> > > > providing date in the same format. Again without explicitly specifying
> > > > the analyzer. Both queries came back empty even though when I pulled
> > > > the documents using queries based on different fields I can see the
> > > > date is there
> > > > 2. I did pretty much the same but changed the field type to "string"
> > > > with the same result.
>
> > > > What am I missing here?
Reply | Threaded
Open this post in threaded view
|

Re: making date field work

Clinton Gormley-2
Hi Michael

> Lesson learned. But to make it easier on other people - would it make
> sense to introduce a way to make upload "strict" - meaning that all
> fields in the data json have to be mapped upfront. That's the mode I
> would use and it would definitely save me some grief.

Have a look at the { dynamic: "strict" } setting on this page:
http://www.elasticsearch.org/guide/reference/mapping/object-type.html

clint