Elasticsearch之Mapping创建

如何显示定义一个Mapping

Index-控制当前字段是否被索引。如果设置成false,该字段不可被索引

PUT users
{
  "mappings": {
    "properties": {
      "firstname":{
        "type":"text"
      },
      "lastname":{
        "type":"text"
      },
      "mobile":{
        "type": "text",
        "index": false
      }
    }
  }
}

四种不同的Index Options配置,可以控制倒排索引的内容

docs-记录doc id

  freqs-记录doc id和term frequencies

  positions-记录doc id/term frequencies/term position

  offsets-doc id/term frequencies/term position/character offsets

text类型默认记录position,其他默认docs

记录内容越多,占用的存储空间越大

PUT users
{
  "mappings": {
    "properties": {
      "firstname":{
        "type":"text"
      },
      "lastname":{
        "type":"text"
      },
      "mobile":{
        "type": "text",
        "index": false
      },
      "bio":{
        "type": "text",
        "index_options": "offsets"
      }
    }
  }
}

null_value

需要对null值搜索 只有Keyword类型支持

PUT users
{
  "mappings": {
    "properties": {
      "firstname":{
        "type":"text"
      },
      "lastname":{
        "type":"text"
      },
      "mobile":{
        "type": "keyword",
        "null_value": "null"
      }
    }
  }
}

PUT users/_doc/1
{
  "firstname":"zhouqiang",
  "lastname":"qiang",
  "mobile":null
}
GET users/_search?q=mobile:NULL

copy_to设置

_all在7中被copy_to所代替

满足一些特定的搜索需求

copy_to将字段的数值拷贝到目标字段,不出现在_source中

原文地址:https://www.cnblogs.com/fat-girl-spring/p/12457008.html