Elastic的字符串属性分成:keyword 和 text ,一般我们会把所有字符串设置为 keyword:
默认字段属性的设置规则:
PUT /test_idx { "settings": { "number_of_shards": 3, "number_of_replicas": 1 }, "mappings": { "month": { "dynamic": "true", "dynamic_templates": [ { "regex_template": { "match_pattern": "regex", "mapping": { "type": "keyword" }, "match": "^(?!.*?_time|is_.*|.*?_cnt|.*?_count|.*?_dbl|.*?_double|.*?_obj|.*?_object).*$" } }, { "time_template": { "mapping": { "format": "strict_date_time || yyyy-MM-dd HH:mm:ss || epoch_millis || epoch_second || yyyy-MM-dd", "type": "date" }, "match": "*_time" } }, { "double_template": { "mapping": { "type": "double" }, "match": "*_dbl" } }, { "double_template": { "mapping": { "type": "double" }, "match": "*_double" } }, { "integer_template": { "mapping": { "type": "integer" }, "match": "is_*" } }, { "long_template": { "mapping": { "type": "integer" }, "match": "*_cnt" } }, { "long_template": { "mapping": { "type": "integer" }, "match": "*_count" } }, { "object_template": { "mapping": { "type": "object" }, "match": "*_obj" } }, { "object_template": { "mapping": { "type": "object" }, "match": "*_object" } } ] } } }
总结一下(其实主要是围绕着是否查询关键词会被分词):
对于 keyword 的字段,以下各个查找的意义:
keyword + match : 全等匹配
keyword + prefix : mysql的like 搜索 - 字符串不分词模糊匹配 - 左边没有%而右边有 (等同于 wildcard 的"关键词*")
keyword + text : 查询会失败
keyword + query_string : 完全匹配才会有结果
keyword + wildcard : 如果*keyowrd* 则等价于MySQL的%keyword% ,如果 *keyword 等价于 %keyword 注意此刻右边是没有模糊百分号匹配的, keyword*同理, 如果wildcard 是没有*号的话,则等同于字符串完全匹配
原文:https://www.cnblogs.com/xuweiqiang/p/14891011.html