Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date format parsed from query to builder defaults to current date with fixed format #7

Open
oguennec opened this issue Jun 10, 2016 · 7 comments

Comments

@oguennec
Copy link
Contributor

@dncrews
When parsed into the builder, date fields from a query default to the current date with fixed format (calendar default format). Only some ISO formats are recognized

@dncrews
Copy link
Owner

dncrews commented Jun 29, 2016

What do you mean by this? I hesitate to add something like moment in here if that can be avoided.

@oguennec
Copy link
Contributor Author

With this fix, a format field is added next to a date, for instance:

      "range": {
        "datePublished": {
          "lte": "2013-03-08",
          "format": "yyyy-MM-dd"
        }
      }

Hence the builder knows the format to parse a string to a date.

MomentJS/Angular-MomentJS appears to be the solution for the job.

Without this fix, the format is hard coded and any date field in "stored" queries must follow this format so that the query can be parsed by the builder.

Also without the fix, a date in a query defaults to the current date when parsed through the builder.

I have created a search application that uses the builder in this way with a demo. I hope this helps to illustrate my understanding on how to use your builder.

@tienvx
Copy link

tienvx commented Jun 30, 2016

Just a note: if we add 'format' key to the rule, like this:

{"query":{"filtered":{"filter":{"and":[{"term":{"startRegistered":"2016-06-30T13:37:06+0700", "format": "yyyy-MM-dd'T'HH:mm:ssZ"}}]}}},"sort":[],"from":0,"size":100}

elasticsearch will return an error:

[term] query does not support different field names, use [bool] query instead

I suggest to use one format only 'yyyy-MM-dd'T'HH:mm:ssZ' and then use another datepicker library that include timepicker e.g. angular-bootstrap-datetimepicker

@oguennec
Copy link
Contributor Author

Elastic search understands multiple date formats so it seems interesting to have this feature in the builder. Also setting the time is not always relevant in a range search so date only format are useful. But I agree that when time is required, it would be nice to have a timepicker. I suggest ui.boostrap.timepicker. This should be a request for a new feature in a separate issue though.

oguennec added a commit to oguennec/angular-elastic-builder that referenced this issue Jun 30, 2016
@dncrews
Copy link
Owner

dncrews commented Jun 30, 2016

If it breaks elasticsearch as is, I'm not interested in having it. This is first and foremost an Elasticsearch query builder.

@dncrews
Copy link
Owner

dncrews commented Jun 30, 2016

format doesn't sound like part of the query. It sounds like part of the configuration.

Thoughts about doing something like:

'test.date': { type: 'date', format: 'YYYY-mm-dd' },

This sounds right to me. Elasticsearch supports multiple date formats, but each field in ES should only be standardized into a single format. I think we should rewrite it to be like this.

@dncrews
Copy link
Owner

dncrews commented Jun 30, 2016

Or perhaps passing your own formatter method?

oguennec added a commit to oguennec/angular-elastic-builder that referenced this issue Jul 12, 2016
oguennec added a commit to oguennec/angular-elastic-builder that referenced this issue Jul 12, 2016
oguennec added a commit to oguennec/angular-elastic-builder that referenced this issue Jul 13, 2016
oguennec added a commit to oguennec/angular-elastic-builder that referenced this issue Jul 13, 2016
oguennec added a commit to oguennec/angular-elastic-builder that referenced this issue Jul 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants