Elasticsearch mappings

dynamic

true:插入值的字段没在mappings中定义,会新增字段
false:插入值的字段没在mappings中定义,不会新增字段,但也不会报错
strict:插入值的字段没在mappings中定义,会报错

PUT my_index
{
  "mappings": {
    "doc": {
      "dynamic": false,
      "properties": {
        "title": {
          "type": "text"
        },
        "name": {
          "type": "keyword"
        },
        "age": {
          "type": "integer"
        }
      }
    }
  }
}
GET my_index/_mapping
PUT my_index/doc/1
{
  "title": "hello baozi",
  "desc": "nothing"
}
GET my_index/doc/_search
{
  "query": {
    "match": {
      "title": "hello"
    }
  }
}
GET my_index/doc/_search
{
  "query": {
    "match": {
      "desc": "nothing"
    }
  }
}

copy_to

copy_to的字段不会被存储

PUT my_index
{
  "mappings": {
    "doc": {
      "properties": {
        "first_name": {
          "type": "text",
          "copy_to": "full_name"
        },
        "last_name": {
          "type": "text",
          "copy_to": "full_name"
        },
        "full_name": {
          "type": "text"
        }
      }
    }
  }
}
PUT my_index/doc/1
{
  "first_name": "B",
  "last_name": "aozi"
}
GET my_index/doc/_search
{
  "query": {
    "match": {
      "full_name": {
        "query": "B aozi",
        "operator": "and"
      }
    }
  }
}

index

运行之后会保存,因为index设置为false

PUT my_index
{
  "mappings": {
    "doc": {
      "properties": {
        "cookie": {
          "type": "text",
          "index": false
        }
      }
    }
  }
}
PUT my_index/doc/1
{
  "cookie": "name=baozi"
}
GET my_index/doc/_search
{
  "query": {
    "match": {
      "cookie": "name"
    }
  }
}

index_options

用于控制倒排索引记录的内容,text类型默认为position

  • docs 记录doc id
  • freqs 记录doc id、term frequencies
  • positions 记录doc id、term frequencies、term position
  • offsets 记录doc id、term frequencies、term position和character offsets

null_value

遇到null值时怎么处理

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容