首页 > 其他 > 详细

Elastic的字符串查找

时间:2021-06-16 22:19:23      阅读:30      评论:0      收藏:0      [点我收藏+]

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"
          }
        }
      ]
    }
  }
}  
View Code

 

总结一下(其实主要是围绕着是否查询关键词会被分词):

对于 keyword 的字段,以下各个查找的意义:

keyword + match : 全等匹配

keyword + prefix : mysql的like 搜索 - 字符串不分词模糊匹配 - 左边没有%而右边有 (等同于 wildcard 的"关键词*")

keyword + text :  查询会失败

keyword + query_string : 完全匹配才会有结果

keyword + wildcard : 如果*keyowrd* 则等价于MySQL的%keyword% ,如果 *keyword 等价于 %keyword 注意此刻右边是没有模糊百分号匹配的, keyword*同理, 如果wildcard 是没有*号的话,则等同于字符串完全匹配

 

Elastic的字符串查找

原文:https://www.cnblogs.com/xuweiqiang/p/14891011.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!