重新索引后Elasticsearch不遵循_mapping [英] Elasticsearch doesn't obey _mapping after reindex
问题描述
我在弹性搜索中存储了一个名为 last_post_date 的字段。
I have a field called last_post_date stored in elasticsearch.
它显示为:
...
"last_post_date": "1485281760000",
...
并且映射为:
"last_post_date": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
现在,我创建一个新索引,其映射为:
Now I create a new index with the mapping as:
...
"last_post_date": {
"type": "date",
"format": "epoch_millis",
"index": true,
"doc_values": true
},
...
并通过以下方式进行完全重新索引:
http://127.0.0.1:9200/_reindex
And do a full reindex via: http://127.0.0.1:9200/_reindex
问题在于,即使重新索引了字段的值存储为strin在映射显示时用g代替日期:
The problem is that even after reindexing the field's value is stored as string instead of date while the mapping shows:
...
"last_post_date": {
"type": "date",
"store": true,
"format": "epoch_millis"
},
...
为什么知道?
推荐答案
您会在源代码中看到,例如格式为 1485281760000
的类似字符串的时间戳,将不会更改,并且将始终反映您发送给Elasticsearch的完全相同的JSON。
What you see in the source, i.e. a string-like timestamp of the form "1485281760000"
will not change and will always reflect the exact same JSON you sent to Elasticsearch.
但是,在被索引时,字符串 1485281760000
确实会被解释并索引为长值 1485281760000
。
However, when being indexed, the string "1485281760000"
will be indeed interpreted and indexed as the long value 1485281760000
.
如果您要更改JSON源,则将使用较长的时间戳而不是字符串时间戳进行发送,如下所示,那么源将显示您的较长时间戳。
If you were to change the JSON source you're sending with a long timestamp instead of a string timestamp, like below, then the source will show your a long timestamp.
...
"last_post_date": 1485281760000,
...
长话短说:
- 您在
_source
中看到的就是发送给ES的内容 - 将根据您创建的映射来解释和索引源的每个字段,即,字符串时间戳将被强制为长整数,并被解释为格式为
epoch_millis
的日期。 - 如果某些字段值无法根据您的映射正确地解释,索引和强制转换,则会出现错误,并且文档也将完全不被索引。
- what you see in the
_source
is exactly what you sent to ES - each field of the source is interpreted and indexed according to the mapping you've created, i.e. the string timestamp will be coerced to a long and interpreted as a date of the format
epoch_millis
- if some field value cannot be properly interpreted, indexed, coerced according to your mapping, you'll get an error and the document won't be indexed at all.
这篇关于重新索引后Elasticsearch不遵循_mapping的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!