elasticsearch新增字段如何设置不索引

elasticsearch 版本为6.1.4
索引的文档包含的字段种类较多,并且后续会补充新的类型,但用于查询的字段只有固定的6,7个,如何设置新增字段不索引?
这里我所表达的“新增字段”是指在创建索引时mapping中没有指定的字段,后续插入时自己判定类型的字段。

阅读 7.1k
1 个回答

已解决,创建索引时可将dynamic设为false。

PUT /my-index
{
  "mappings": {
    "dynamic": "false",
    "properties": {
      "age":    { "type": "integer" },  
      "email":  { "type": "keyword"  }, 
      "name":   { "type": "text"  }     
    }
  }
}

dynamic相关描述:
By default, when a previously unseen field is found in a document, Elasticsearch will add the new field to the type mapping. This behaviour can be disabled, both at the document and at theobjectlevel, by setting thedynamicparameter tofalse(to ignore new fields) or tostrict(to throw an exception if an unknown field is encountered).

官方文档:
https://www.elastic.co/guide/...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进