Chapter 6. Mapping and Analysis
While playing around with the data in our index, we notice something odd.
Something seems to be broken: we have 12 tweets in our indices, and only one
of them contains the date 2014-09-15, but have a look at the total hits
for the following queries:
GET/_search?q=2014#12resultsGET/_search?q=2014-09-15#12results!GET/_search?q=date:2014-09-15#1resultGET/_search?q=date:2014#0results!
Why does querying the _all field for the full date
return all tweets, and querying the date field for just the year return no
results? Why do our results differ when searching within the _all field or
the date field?
Presumably, it is because the way our data has been indexed in the _all
field is different from how it has been indexed in the date field.
So let’s take a look at how Elasticsearch has interpreted our document
structure, by requesting the mapping (or schema definition)
for the tweet type in the gb index:
GET/gb/_mapping/tweet
This gives us the following:
{"gb":{"mappings":{"tweet":{"properties":{"date":{"type":"date","format":"dateOptionalTime"},"name":{"type":"string"},"tweet":{"type":"string"},"user_id":{"type":"long"}}}}}}
Elasticsearch has dynamically generated a mapping for us, based on what it
could guess about our field types. The response shows us that the date field
has been recognized as a field of type date. The _all field isn’t mentioned because it is a default field, but we know that the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access