亲,只收二进制

时间字段如何实现模糊检索和全文检索?

Elasticsearch | 作者 laoyang360 | 发布于2017年08月18日 | 阅读数:3373

现在mapping时间设定:
"update_time": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
我查了下api,貌似只支持精确匹配,或者做范围检索。

问题如下:
1、对于日期:"2017-08-16 23:54:35", 我想通过检索 "2017", 获取这条记录。
用wildcardQuery,通过"*2017*"
报错如下:
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to create query: {\n \"wildcard\" : {\n \"update_time\" : {\n \"wildcard\" : \"2017-08-18\",\n \"boost\" : 1.0\n }\n }\n}","index_uuid":"WzAkDsN-QrKjtPOKqz0PLQ","index":"xxindex"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"letindex","node":"BosI3A-bSJaVM0LHULDC9A","reason":{"type":"query_shard_exception","reason":"failed to create query: {\n \"wildcard\" : {\n \"update_time\" : {\n \"wildcard\" : \"2017-08-18\",\n \"boost\" : 1.0\n }\n }\n}","index_uuid":"WzAkDsN-QrKjtPOKqz0PLQ","index":"letindex","caused_by":{"type":"illegal_argument_exception","reason":"Cannot extract a term from a query of type class org.apache.lucene.search.IndexOrDocValuesQuery: update_time:[1503014400000 TO 1503100799999]"}}}]},"status":400}

用matchQuery,通过"2017",
检索为空。

想问下,如何设置,才能支持wildcardQuery和matchQuery?
已邀请:

linyongzhi

赞同来自:

如果时间字段没有什么特殊要求,可以设置成字符串类型

要回复问题请先登录注册