Home > database >  In Elasticsearch, can I index date strings embedded in a document as a date type?
In Elasticsearch, can I index date strings embedded in a document as a date type?

Time:09-17

I am indexing documents with many embedded date strings of the format "<month> <day>, <year>". Is it possible in Elasticsearch to recognize these strings as date types during the indexing process such that I can later query the documents using date ranges in the query, for example:

find all documents that have any embedded date >= 2021-01-01 and the phrase "held on" within 5 words of the date

The problem is that the number of embedded dates within a document varies greatly (some documents have tens of dates, while others may have hundreds), so I don't see a way to extract them into separate, predefined fields.

CodePudding user response:

only if you extract and map these into their own timestamp field, Elasticsearch won't natively pull that out

you could do that with an ingest pipeline for eg, using grok or dissect and then using date on the extracted field

you could also use a runtime field, but that's a little more complex, and the above option is more efficient in the long run

  • Related