Eslaticsearch创建索引时mapping参数解析

- dynamic 参数动态添加新字段
 
- -true 允许自动将检测到的新字段加到映射中(默认的)
 - -false 不允许自动新增字段,文档可以写入,但无法对字段进行搜索等操作。不会添加在映射中。且在kibana上面看到的新字段上会显示一个黄色感叹号,刷新index pattern也无效。
 - -strict 文档不能写入,写入会报错
 
- analyzer 指定分词器
 - ignore_above 超过ignore_above的字符串将不会被索引或存储
 
PUT test_index{
  "mappings": {
    "doc":{
      "properties": {
        "message":{
          "type": "keyword",
          "ignore_above": 20  #字段值超过20个字符的字符串不会被索引或者存储
        }
      }
    }
  }
}
POST test_index/doc/_bulk
{"index":{"_id":1}}
{"message":"test message"}
{"index":{"_id":2}}
{"message":"test message  with some long stacktrace messages test test"}
GET test_index/_search
{
  "size": 0, 
  "aggs": {
    "message": {
      "terms": {
        "field": "message",
        "size": 10
      }
    }
  }
}----------------------->只能得到第一个桶
      "buckets": [
        {
          "key": "test message",
          "doc_count": 1
        }
      ]
GET test_index/_search    
{
  "query": {
    "query_string": {
      "default_field": "message",
      "query": "*message*"
    }
  }
}
------------->只能搜索到id为1的文档
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "test_index",
        "_type": "doc",
        "_id": "1",
        "_score": 1,
        "_source": {
          "message": "test message"
        }
      }
    ]
- index true | false 控制字段是否被索引,默认为true。
 
- doc_values 本质是一个序列化的列式存储 。列式存储适用于聚合,排序,脚本操作。
 
- true 默认对除了analyzed strings以外的所有字段开启。
 - false 不能用于聚合、排序和脚本操作
 
- fields 对同一字段采用不同类型配置。比如string字段映射为text做全文搜索,映射为keyword做聚合和排序
 
PUT test_index{
  "mappings": {
    "doc":{
      "properties": {
        "name":{
          "type": "text",     #text类型,用于全文检索
          "fields": {
            "keyword":{    #name.keyword
              "type": "keyword"   #keyword类型,用于排序和聚合
            }
          }
        }
      }
    }
  }
}
PUT test_index/doc/1
{
  "name":"Jack smis"
}
PUT test_index/doc/2
{
  "name":"Jack"
}
GET test_index/_search
{
  "query": {
    "match": {
      "name": "jack"      #text类型字段
    }
  },
  "sort": [
    {
      "name.keyword": {    #keyword类型字段
        "order": "desc"
      }
    }
  ],
  "aggs": {
    "name_count": {
      "value_count": {
        "field": "name.keyword"   #keyword类型字段
      }
    }
  }
}
properties object字段或nested字段包含子字段,称为properties。properties可以是任何数据类型
PUT test_index{
  "mappings": {
    "doc": {
      "properties": {
        "dev":{                #object类型字段
          "properties": {
            "name":{
              "type":"text"
            },
            "age":{
              "type":"integer"
            }
          }
        },
        "rel":{
          "type": "nested",    #nested类型字段
          "properties": {
            "age":{
              "type":"integer"
            },
            "name":{
              "type":"text"
            }
          }
        }
      }
    }
  }
}
PUT test_index/doc/1
{
  "dev":{
    "name":"john smith",
    "age":23
  },
  "rel":[
    {
      "name":"alice white",
      "age":34
    },
    {
      "name":"peter brown",
      "age":26
    }
    ]
}
norms 时间评分因子,如果不关心评分可以禁用
以上是 Eslaticsearch创建索引时mapping参数解析 的全部内容, 来源链接: utcz.com/z/515835.html

