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

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

阅读 593
评论
    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/...

    评论 赞赏
      撰写回答

      登录后参与交流、获取后续更新提醒