zoukankan      html  css  js  c++  java
  • ElasticSearch 种映射参数详解-理论学习02

    版权申明:

    本文仅适用于学习,更多内容请访问原创作者:

    微信公众号:江南一点雨
    博客:https://www.javaboy.org/

    下面有用到postman、kibana

    一、ElasticSearch 中地理类型和特殊类型

    1.地理类型

    使用场景:

    • 查找某一个范围内的地理位置
    • 通过地理位置或者相对中心点的距离来聚合文档
    • 把距离整个到文档的评分中
    • 通过距离对文档进行排序

    1.1 geo_point

    geo_point 就是一个坐标点,定义方式如下:

    # PUT
    192.168.246.130:9200/people
    {
        "mappings":{
            "properties":{
                "location":{
                    "type":"geo_point"
                }
            }
        }
    }
    

    创建时指定字段类型,存储的时候,有四种方式:

    # PUT
    192.168.246.130:9200/people/_doc/1
    {
        "location":{
            "lat":34.27,
            "lon":108.94
        }
    }
    
    # PUT
    192.168.246.130:9200/people/_doc/2
    {
      "location":"34.27,108.94"
    }
    
    # PUT
    192.168.246.130:9200/people/_doc/3
    {
      "location":"uzbrgzfxuzup"
    }
    
    # PUT
    192.168.246.130:9200/people/_doc/4
    {
      "location":[108.94,34.27]
    }
    

    这里要注意的是,使用数组描述,先经度后纬度。longitude and latitude 经纬度。

    地址位置转: geo_hash:http://www.csxgame.top/#/

    1.2 geo_shape

    Geo_JSON ElasticSearch 备注
    Point point 一个由经纬度描述的点
    LineString linestring 一个任意的线条,由两个以上的点组成
    Polygon polygon 一个封闭的多边形
    MultiPoint multipoint 一组不连续的点
    MultiLineString multilinestring 多条不关联的线
    MutiPolygon multipolygon 多个多边形
    GeometryCollection geometrycollection 几何对象的集合
    circle 一个圆形
    envelope 通过左上角和右下角两个点确定的矩形

    指定geo_shape 类型:

    #PUT
    192.168.246.130:9200/car
    {
      "mappings": {
        "properties": {
          "location":{
            "type": "geo_shape"
          }
        }
      }
    }
    

    添加文档时需要指定具体的类型:

    #PUT
    192.168.246.130:9200/car/_doc/1
    {
      "location":{
        "type":"linestring",
        "coordinates": [[108.94,34.27],[100,33]]
      }
    }
    

    如果时linestring,如下:

    #PUT
    192.168.246.130:9200/car/_doc/2
    {
      "location":{
        "type":"linestring",
        "coordinates": [[108.94,34.27],[100,33]]
      }
    }
    

    2.特殊类型

    2.1 IP

    存储 IP 地址,类型是 ip:

    #PUT
    192.168.246.130:9200/blog
    {
      "mappings": {
        "properties": {
          "address":{
            "type": "ip"
          }
        }
      }
    }
    

    添加文档:

    #PUT
    192.168.246.130:9200/blog/_doc/1
    {
      "address":"192.168.91.1"
    }
    

    搜索文档:

    #GET
    192.168.246.130:9200/blog/_search
    {
      "query": {
        "term": {
          "address": "192.168.0.0/16"
        }
      }
    }
    

    2.2 token_content

    用于统计字符串分词后的词项个数。

    #GET
    192.168.246.130:9200/blog/
    {
      "mappings": {
        "properties": {
          "title":{
            "type": "text",
            "fields": {
              "length":{
                "type":"token_count",
                "analyzer":"standard"
              }
            }
          }
        }
      }
    }
    

    相当于新增了 title.length 字段用来统计分词后词项的个数。

    添加文档:

    #GET
    192.168.246.130:9200/blog/_doc/1
    {
      "title":"li si"
    }
    

    可以通过 token_count 去查询:

    #GET
    192.168.246.130:9200/blog/_search
    {
      "query": {
        "term": {
          "title.length": 2
        }
      }
    }
    

    二、 ElasticSearch 23 种映射参数详解

    1. analyzer

    定义文本字段的分词器。默认对索引和查询都是有效的。

    若不用分词器,我们先来看下索引的结果,创建一个索引并添加一个文档:

    #PUT
    192.168.246.130:9200/blog/_doc/1
    {
      "title":"定义文本字段的分词器。默认对索引和查询都是有效的。"
    }
    

    查看词条向量( term vectors)

    #PUT
    192.168.246.130:9200/blog/_termvectors/1
    {
      "fields": ["title"]
    }
    

    查看结果如下:

    {
      "_index" : "blog",
      "_type" : "_doc",
      "_id" : "1",
      "_version" : 1,
      "found" : true,
      "took" : 0,
      "term_vectors" : {
        "title" : {
          "field_statistics" : {
            "sum_doc_freq" : 22,
            "doc_count" : 1,
            "sum_ttf" : 23
          },
          "terms" : {
            "义" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 1,
                  "start_offset" : 1,
                  "end_offset" : 2
                }
              ]
            },
            "分" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 7,
                  "start_offset" : 7,
                  "end_offset" : 8
                }
              ]
            },
            "和" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 15,
                  "start_offset" : 16,
                  "end_offset" : 17
                }
              ]
            },
            "器" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 9,
                  "start_offset" : 9,
                  "end_offset" : 10
                }
              ]
            },
            "字" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 4,
                  "start_offset" : 4,
                  "end_offset" : 5
                }
              ]
            },
            "定" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 0,
                  "start_offset" : 0,
                  "end_offset" : 1
                }
              ]
            },
            "对" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 12,
                  "start_offset" : 13,
                  "end_offset" : 14
                }
              ]
            },
            "引" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 14,
                  "start_offset" : 15,
                  "end_offset" : 16
                }
              ]
            },
            "效" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 21,
                  "start_offset" : 22,
                  "end_offset" : 23
                }
              ]
            },
            "文" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 2,
                  "start_offset" : 2,
                  "end_offset" : 3
                }
              ]
            },
            "是" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 19,
                  "start_offset" : 20,
                  "end_offset" : 21
                }
              ]
            },
            "有" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 20,
                  "start_offset" : 21,
                  "end_offset" : 22
                }
              ]
            },
            "本" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 3,
                  "start_offset" : 3,
                  "end_offset" : 4
                }
              ]
            },
            "查" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 16,
                  "start_offset" : 17,
                  "end_offset" : 18
                }
              ]
            },
            "段" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 5,
                  "start_offset" : 5,
                  "end_offset" : 6
                }
              ]
            },
            "的" : {
              "term_freq" : 2,
              "tokens" : [
                {
                  "position" : 6,
                  "start_offset" : 6,
                  "end_offset" : 7
                },
                {
                  "position" : 22,
                  "start_offset" : 23,
                  "end_offset" : 24
                }
              ]
            },
            "索" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 13,
                  "start_offset" : 14,
                  "end_offset" : 15
                }
              ]
            },
            "认" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 11,
                  "start_offset" : 12,
                  "end_offset" : 13
                }
              ]
            },
            "词" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 8,
                  "start_offset" : 8,
                  "end_offset" : 9
                }
              ]
            },
            "询" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 17,
                  "start_offset" : 18,
                  "end_offset" : 19
                }
              ]
            },
            "都" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 18,
                  "start_offset" : 19,
                  "end_offset" : 20
                }
              ]
            },
            "默" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 10,
                  "start_offset" : 11,
                  "end_offset" : 12
                }
              ]
            }
          }
        }
      }
    }
    

    可以看到,默认情况下,中文就是一个字一个字的分,这种分词方式没有任何意义。

    如果这样分词,查询就只能按照一个字一个字来查,像下面这样:

    #GET
    192.168.246.130:9200/blog/_search
    {
      "query": {
        "term": {
          "title": "定"
        }
      }
    }
    

    这样就没有意义了。

    所以,我们要根据实际情况,配置合适的分词器。
    给字段设定分词器:

    #PUT
    192.168.246.130:9200/blog
    {
      "mappings": {
        "properties": {
          "title":{
            "type":"text",
            "analyzer": "ik_smart"
          }
        }
      }
    }
    

    存储文档:

    #PUT
    192.168.246.130:9200/blog/_doc/1
    {
      "title":"定义文本字段的分词器。默认对索引和查询都是有效的。"
    }
    

    查看词条向量:

    #GET
    192.168.246.130:9200/blog/_termvectors/1
    {
      "fields": ["title"]
    }
    

    查询结果如下

    {
      "_index" : "blog",
      "_type" : "_doc",
      "_id" : "1",
      "_version" : 1,
      "found" : true,
      "took" : 1,
      "term_vectors" : {
        "title" : {
          "field_statistics" : {
            "sum_doc_freq" : 12,
            "doc_count" : 1,
            "sum_ttf" : 13
          },
          "terms" : {
            "分词器" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 4,
                  "start_offset" : 7,
                  "end_offset" : 10
                }
              ]
            },
            "和" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 8,
                  "start_offset" : 16,
                  "end_offset" : 17
                }
              ]
            },
            "字段" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 2,
                  "start_offset" : 4,
                  "end_offset" : 6
                }
              ]
            },
            "定义" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 0,
                  "start_offset" : 0,
                  "end_offset" : 2
                }
              ]
            },
            "对" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 6,
                  "start_offset" : 13,
                  "end_offset" : 14
                }
              ]
            },
            "文本" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 1,
                  "start_offset" : 2,
                  "end_offset" : 4
                }
              ]
            },
            "有效" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 11,
                  "start_offset" : 21,
                  "end_offset" : 23
                }
              ]
            },
            "查询" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 9,
                  "start_offset" : 17,
                  "end_offset" : 19
                }
              ]
            },
            "的" : {
              "term_freq" : 2,
              "tokens" : [
                {
                  "position" : 3,
                  "start_offset" : 6,
                  "end_offset" : 7
                },
                {
                  "position" : 12,
                  "start_offset" : 23,
                  "end_offset" : 24
                }
              ]
            },
            "索引" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 7,
                  "start_offset" : 14,
                  "end_offset" : 16
                }
              ]
            },
            "都是" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 10,
                  "start_offset" : 19,
                  "end_offset" : 21
                }
              ]
            },
            "默认" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 5,
                  "start_offset" : 11,
                  "end_offset" : 13
                }
              ]
            }
          }
        }
      }
    }
    

    这样就可以通过词去搜索了:

    #GET 
    192.168.246.130:9200/blog/_search
    {
      "query": {
        "term": {
          "title": "索引"
        }
      }
    }
    

    2. search_analyzer

    查询时候的分词器。默认情况下,如果没有配置 search_analyzer,则查询时,首先查看有没有 search_analyzer 。

    • 有。就用search_analyzer 来进行分词,
    • 没有 。则看有没有 analyzer ,如果有,则有 analyzer 来进行分词,否则使用 es 默认的分词器。

    3. normalizer

    normalizer 参数用于解析前(索引或者查询)的标准化配置。
    比如,在es种,对于一些我们不想切分的字符串,我们通常会将其设置为keyword,搜索时也是使用整个词进行搜索。如果在索引前没有做好数据清洗,导致大小写不一致,例如 blog 和 BLOG ,此时,我们可以使用 normalizer 在索引之前以及查询之前进行文档的标准化。

    先来一个反例,创建一个名为 blog 的索引,设置 author 字段类型为 keyword:

    #PUT 
    192.168.246.130:9200/blog
    {
      "mappings": {
        "properties": {
          "author":{
            "type": "keyword"
          }
        }
      }
    }
    

    添加两个文档:

    #PUT 
    192.168.246.130:9200/blog/_doc/1
    {
      "author":"blog"
    }
    
    #PUT 
    192.168.246.130:9200/blog/_doc/2
    {
      "author":"BLOG"
    }
    

    然后进行搜索:

    #GET
    192.168.246.130:9200/blog/_search
    {
      "query": {
        "term": {
          "author": "BLOG"
        }
      }
    }
    

    大写关键字可以搜索到大写的文档,小写关键字可以搜到小的文档。

    如果使用了normalizer,可以在索引和查询时,分别对文档进行预处理。

    normalizer 定义方式如下:

    #PUT 
    192.168.246.130:9200/blog/
    {
      "settings": {
        "analysis": {
          "normalizer":{
            "my_normalizer":{
              "type":"custom",
              "filter":["lowercase"]
            }
          }
        }
      }, 
      "mappings": {
        "properties": {
          "author":{
            "type": "keyword",
            "normalizer":"my_normalizer"
          }
        }
      }
    }
    

    在 settings 种定义 normalizer,然后在 mappings 种引用。

    测试方式和前面一致。此时查询的时候,大写关键字也可以查询到小写文档,因为无论是索引还是查询,都会将大写转为小写。

    三、ElasticSearch 如何配置某个字段的权重-学习

    1. boost

    boost 有两种使用思路,一种就是定义 mappings 的时候使用,在指定字段类型时使用;另一种就是在查询时使用。

    在实际开发种建议使用后者,前者有问题;如果不重新索引文档,权重无法修改。

    mappings 中使用 boost (不推荐):

    PUT blog
    {
      "mappings": {
        "properties": {
          "content":{
            "type": "text",
            "boost": 2
          }
        }
      }
    }
    

    另一种方式就是在查询的时候,指定 boost

    GET blog/_search
    {
      "query": {
        "match": {
          "content": {
            "query": "你好",
            "boost": 2
          }
        }
      }
    }
    

    2. coerce

    coerce 用来清除脏数据,默认为 true

    例如一个数字,在JSON中,用户可能写错了:

    {"age":"99"}
    

    或者:

    {"age":"99.0"}
    

    这些都不是正确的数字格式。通过 coerce 可以解决该问题。

    默认情况下,以下操作没问题,就是 coerce 起作用:

    PUT blog
    {
      "mappings": {
        "properties": {
          "age":{
            "type": "integer"
          }
        }
      }
    }
    
    POST blog/_doc
    {
      "age":"99.0"
    }
    

    如果需要修改 coerce ,方式如下:

    PUT blog
    {
      "mappings": {
        "properties": {
          "age":{
            "type": "integer",
            "coerce": false
          }
        }
      }
    }
    
    POST blog/_doc
    {
      "age":99
    }
    

    coerce 修改为 false 之后,数字就只能是数字了,不可以是字符串,该字段传入字符串会报错。

    3. copy_to

    这个属性,可以将多个字段的值,复制到同一个字段中。

    定义方式如下:

    PUT blog
    {
      "mappings": {
        "properties": {
          "title":{
            "type": "text",
            "copy_to": "full_content"
          },
          "content":{
            "type": "text",
            "copy_to": "full_content"
          },
          "full_content":{
            "type": "text"
          }
        }
      }
    }
    
    PUT blog/_doc/1
    {
      "title":"你好江南一点雨",
      "content":"当 coerce 修改为 false 之后,数字就只能是数字了,不可以是字符串,该字段传入字符串会报错。"
    }
    
    GET blog/_search
    {
      "query": {
        "term": {
          "full_content": "当"
        }
      }
    }
    

    3. doc_values 和 fieldata

    es 中的搜索主要是用到倒排索引,doc_values 参数是为了加快排序,聚合操作而生的。当建立倒排索引的时候,会额外加列式存储映射。

    doc_values 默认是开启的,如果确定某个字段不需要排序或者不需要聚合,那么可以关闭 doc_values。

    大部分的字段在索引时都会生成doc_values,除了text。text 字段在查询时会生成一个 fielddata 的数据结构,fieldata 在字段首次被聚合、排序的时候生成。

    doc_values fielddata
    索引时创建 使用时动态创建
    磁盘 内存
    不占用内存 不占用磁盘
    索引速度稍微低 文档很多时,动态创建慢

    doc_values 默认开启,fielddata 默认关闭。

    doc_values 演示:

    PUT users
    
    PUT users/_doc/1
    {
      "age":100
    }
    
    PUT users/_doc/2
    {
      "age":99
    }
    
    PUT users/_doc/3
    {
      "age":98
    }
    
    PUT users/_doc/4
    {
      "age":101
    }
    
    GET users/_search
    {
      "query": {
        "match_all": {}
      },
      "sort":[
        {
          "age":{
            "order": "desc"
          }
        }
        ]
    }
    

    由于 doc_values 默认时开启的,所以可以直接使用该字段排序,如果想关闭doc_values,如下:

    PUT users
    {
      "mappings": {
        "properties": {
          "age":{
            "type": "integer",
            "doc_values": false
          }
        }
      }
    }
    
    PUT users/_doc/1
    {
      "age":100
    }
    
    PUT users/_doc/2
    {
      "age":99
    }
    
    PUT users/_doc/3
    {
      "age":98
    }
    
    PUT users/_doc/4
    {
      "age":101
    }
    
    GET users/_search
    {
      "query": {
        "match_all": {}
      },
      "sort":[
        {
          "age":{
            "order": "desc"
          }
        }
        ]
    }
    

    四、ElasticSearch 23种映射参数详解--学习02

    1. dynamic

    2. enabled

    es 默认会索引所有的字段,但是所有的字段可能只需要存储,不需要索引。此时可以通过 enabled 字段来控制。

    PUT blog
    {
      "mappings": {
        "properties": {
          "title":{
            "enabled": false
          }
        }
      }
    }
    
    PUT blog/_doc/1
    {
      "title":"javaboy"
    }
    
    GET blog/_search
    {
      "query": {
        "term": {
          "title": "javaboy"
        }
      }
    }
    

    设置了, enabled 为false之后,就可以通过该字段进行搜索了。

    3. format

    日期格式。 format可以规范日期格式,而且一次可以定义多个format。

    PUT users
    {
      "mappings": {
        "properties": {
          "birthday":{
            "type": "date",
            "format": "yyyy-MM-dd||yyyy-MM-dd HH:mm:ss"
          }
        }
      }
    }
    
    PUT users/_doc/1
    {
      "birthday":"2020-11-11"
    }
    
    PUT users/_doc/2
    {
      "birthday":"2020-11-11 11:11:11"
    }
    
    • 多个日期格式之间,使用|| 符合连接,注意没有空格的
    • 如果用户没有指定日期 format ,默认的日期格式是 strict_date_optional_time||epoch_mills

    另外,所有的日期格式,可以在如下的网址查看:
    https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html

    4. ignore_above

    ignore_above 用于指定分词和索引的字符串最大长度,超过最大长度的话,该字段将不会被索引,这个字段只适用于 keyword 类型。

    PUT blog
    {
      "mappings": {
        "properties": {
          "title":{
            "type": "keyword",
            "ignore_above": 10
          }
        }
      }
    }
    
    PUT blog/_doc/1
    {
      "title":"javaboy"
    }
    
    PUT blog/_doc/2
    {
      "title":"javaboyjavaboyjavaboy"
    }
    
    GET blog/_search
    {
      "query": {
        "term": {
          "title": "javaboyjavaboyjavaboy"
        }
      }
    }
    

    5. ignore_malformed

    ignore_malformated 可以忽略不规则的数据,该参数默认为false。

    PUT users
    {
      "mappings": {
        "properties": {
          "birthday":{
            "type": "date",
            "format": "yyyy-MM-dd||yyyy-MM-dd HH:mm:ss"
          },
          "age":{
            "type": "integer",
            "ignore_malformed": true
          }
        }
      }
    }
    
    PUT users/_doc/1
    {
      "birthday":"2020-11-11",
      "age":99
    }
    
    PUT users/_doc/2
    {
      "birthday":"2020-11-11 11:11:11",
      "age":"abc"
    }
    
    
    PUT users/_doc/2
    {
      "birthday":"2020-11-11 11:11:11aaa",
      "age":"abc"
    }
    

    6. include_in_all

    这个是针对 _all 字段的,但是在es7中,该字段已经被废弃了。

    7. index

    index 属性指定一个字段是否被索引,该属性为true表示字段被索引,false 表示字段不被索引。

    PUT users
    {
      "mappings": {
        "properties": {
          "age":{
            "type": "integer",
            "index": false
          }
        }
      }
    }
    
    PUT users/_doc/1
    {
      "age":99
    }
    
    GET users/_search
    {
      "query": {
        "term": {
          "age": 99
        }
      }
    }
    

    如果 index 为 false ,则不能通过对应的字段搜索。

    8. index_options

    index_options 被控制索引时哪些信息被存储到倒排索引中(用在 text 字段中),有四种取值:

    index_options 备注
    docs 只存储文档编号,默认即此
    freqs 在docs基础上,存储词项频繁
    positions 在freqs基础上,存储词项偏移位置
    offsets 在positions基础上,存储词项开始和结束的字符位置

    9. norms

    norms 对字段评分有用,text 默认开启 norms,如果不是特别需要,不要开启norms。

    10. null_value

    在 es 中,值为null的字段不索引也不可以被搜索,null_value 可以让值为 null的字段显示的可索引、可搜索:

    PUT users
    {
      "mappings": {
        "properties": {
          "name":{
            "type": "keyword",
            "null_value": "javaboy_null"
          }
        }
      }
    }
    
    PUT users/_doc/1
    {
      "name":null,
      "age":99
    }
    
    GET users/_search
    {
      "query": {
        "term": {
          "name": "javaboy_null"
        }
      }
    }
    

    11. position_increment_gap

    被解析的text字段会将 term 的位置考虑进去,目的是为了支持进似查询和短语查询,当我们去索引一含有多个值的 text 时,会在哥哥值之间添加一个假想的空间,将值隔开,这样就可以有效的避免一些无意义的短语匹配,间隙大小通过position_increment_gap来控制,默认100.

    PUT users
    
    PUT users/_doc/1
    {
      "name":["zhang san","li si"]
    }
    
    GET users/_search
    {
      "query": {
        "match_phrase": {
          "name": {
            "query": "sanli"
          }
        }
      }
    }
    
    • sanli 搜索不到,因为两个短语之间有一个假想的空隙,为100
    GET users/_search
    {
      "query": {
        "match_phrase": {
          "name": {
            "query": "san li",
            "slop": 101
          }
        }
      }
    }
    

    可以通过 slop 指定空隙大小。

    也可以在定义索引的时候,指定空隙:

    PUT users
    {
      "mappings": {
        "properties": {
          "name":{
            "type": "text",
            "position_increment_gap": 0
          }
        }
      }
    }
    
    PUT users/_doc/1
    {
      "name":["zhang san","li si"]
    }
    
    GET users/_search
    {
      "query": {
        "match_phrase": {
          "name": {
            "query": "san li"
          }
        }
      }
    }
    

    12. properties

    13. similarity

    similarity 指定文档的评分模型,默认有三种:

    similarity 备注
    BM25 es和luncene默认的评分模型
    classic TF/IDF评分
    boolean boolean模型评分

    14.store

    默认情况下,字段会被索引,也可以搜索,但是不会存储,虽然不会被存储的,但是_source 中有一个字段的备份。如果想将字段存储下路,可以通过配置 store 来实现。

    15. term_vectors

    term_vectors 是通过分词器产生的信息,包括:

    • 一组 terms
    • 每个 term 的位置
    • term 的首字符/尾字符与原始字符串远点的偏移量

    term_vectors取值:

    取值 备注
    no 不存储信息,默认即此
    yes term被存储
    with_positions 在yes的基础上增加位置信息
    with_offset 在yes的基础上增加偏移信息
    with_positions_offsets term、位置、偏移量都存储

    16. fields

    fields 参数可以让同一字段有多种不同的索引方式。例如:

    PUT blog
    {
      "mappings": {
        "properties": {
          "title":{
            "type": "text",
            "fields": {
              "raw":{
                "type":"keyword"
              }
            }
          }
        }
      }
    }
    
    PUT blog/_doc/1
    {
      "title":"javaboy"
    }
    
    GET blog/_search
    {
      "query": {
        "term": {
          "title.raw": "javaboy"
        }
      }
    }
    

    网址如下:
    https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-params.html

    弯弯月亮,只为美好的自己。
  • 相关阅读:
    mscrm 2011 iframe中显示关联实体视图
    Microsoft Dynamic CRM 自定义重复检测功能
    sharepoint 在InfoPath中如何获取当前用户的信息(Profile)(转闪电)
    html页面展示语音流
    socketio请求示例
    RPC框架 redkale maven 打包搭建部署教程
    Nexus Repository Manager 3.0 安装与包上传 Maven、Nuget
    使用java代码配置 Spring Boot 中的 Spring Security 和 Rember me, Cookie记住密码
    CentOs 常用命令
    使用springrestdocs 自动生成接口文档
  • 原文地址:https://www.cnblogs.com/Choleen/p/14131238.html
Copyright © 2011-2022 走看看