es1.x到es2.x有很大的差异,具体看https://www.elastic.co/guide/en/elasticsearch/reference/2.3/breaking-changes-2.0.html。下面罗列一些主要的变化点。html
"_id":{ "path”:"productId" }
之前这种写法,在索引的时候不须要指定_id的值,es自动会把productId的值赋给_id,可是在2.3.4版本中废弃了,因此索引的时候须要显示的指定_id,不指定的话会默认生成一个值。json
"productSkn": { "fields": { "productSkn": { "type": "string", "index": "not_analyzed", "doc_values": true, "fielddata": { "format": "doc_values" } }, "productSkn_ansj": { "type": "string", "store": false, "index_analyzer": "mmseg_complex", "search_analyzer": "mmseg_complex" } }, "type": "multi_field", "path": "just_name" }
这种写法配置了 "path": “just_name”后若是想对productSkn_ansj进行查询,能够数据结构
{ "match" : { “productSkn_ansj" : “xxx" } }
可是在2.3.4版本中废除了 "path": “just_name”,查询productSkn_ansj的时候必须得full name,得这样写:elasticsearch
{ "match" : { “productSkn.productSkn_ansj" : “xxx" } }
使用analyzer代替,若是index analyzer跟search analyzer同样的话不须要写search_analyzer,直接写一个analyzer就好了。ide
not analyzer字段doc_value有效,默认为trueui
analyzer字段fielddata有效,默认为truespa
doc_value、fielddata都是为了聚合计算、排序、在脚本中访问字段值而引入的数据结构,是根据反向索引再次反向出来的一个正向索引,也就是文档到关键词的映射。插件
doc_value是落磁盘的,是预先构建的,也就是构建文档索引的时候。code
fielddata是放内存的,是在一个字段在作聚合、排序、在脚本中访问的时候构建的(命中就不构建了)。orm
Muticast Discovery默认不可用,须要安装相应的插件
这个已经 deprecated,在 2.x 中你还能够用。可是建议作以下修改
{ "query": { "filtered": { "query": { ……. }, "filter": { ……. } } } }
修改成
{ "query": { "bool": { "must": { ……. }, "filter": { ……. } } } }
把 query 和 filter 移到 bool 查询的 must 和 filter 参数之中。
1.4版本
"brandNameCn": { "fields": { "brandNameCn": { "type": "string", "store": false, "analyzer": "ik_complex", "search_analyzer": "ik_complex", "copy_to": ["searchField","searchField_ansj"] }, "brandNameCn_pinyin": { "type": "string", "store": false, "analyzer": "pinyin_analyzer", "search_analyzer": "standard" } }, "type": "multi_field" }
2.3.4版本
{ "brandNameCn": { "copy_to": [ "searchField", "searchField_ansj"], "analyzer": "ik_complex", "type": "string", "fields": { "brandNameCn_pinyin": { "search_analyzer": "standard", "analyzer": "pinyin_analyzer", "type": "string" } } } }
1.4版本 refresh_interval=1
2.3.4版本 refresh_interval=1s