1. Mapping date datatype
参考链接:https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html
mapping:@timestamp type date
range 时值的格式是yyyy-MM-dd HH:mm:ss,但是由于mapping中@timestamp字段类型是date,但是并没有进行设置格式化,如下:
"@timestamp": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
结论:
如果@timestamp字段在mapping中没有设置格式化,在检索的时候是需要加上format的,否则只能细化到yyyy-MM-dd的检索。如果@timestmp字段在mapping中设置了格式化,在检索的时候就不需要进行格式化了,直接传格式正确的值就好了!
2. 测试分析器
使用analyze
API来查看文本是如何被分析的。在查询字符串参数中指定要使用的分析器,被分析的文本做为请求体:
/_analyze?analyzer=standard&text=Text to analyze
结果中每个节点在代表一个词:
{
"tokens": [
{
"token": "text",
"start_offset": 0,
"end_offset": 4,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "to",
"start_offset": 5,
"end_offset": 7,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "analyze",
"start_offset": 8,
"end_offset": 15,
"type": "<ALPHANUM>",
"position": 2
}
]
}
token
是一个实际被存储在索引中的词。
position
指明词在原文本中是第几个出现的。
start_offset
和end_offset
表示词在原文本中占据的位置。
analyze API
对于理解Elasticsearch索引的内在细节是个非常有用的工具。