朱锐---Elasticsearch 1.4 升级 2.3.4
Showing
2 changed files
with
150 additions
and
0 deletions
搜索/Elasticsearch 1.4 升级 2.3.4.md
0 → 100644
1 | +es1.x到es2.x有很大的差别,具体看https://www.elastic.co/guide/en/elasticsearch/reference/2.3/breaking-changes-2.0.html。下面罗列一些主要的变化点。 | ||
2 | + | ||
3 | +**1._id path废弃:** | ||
4 | + | ||
5 | + "_id":{ | ||
6 | + "path”:"productId" | ||
7 | + } | ||
8 | +以前这种写法,在索引的时候不需要指定_id的值,es自动会把productId的值赋给_id,但是在2.3.4版本中废弃了,所以索引的时候需要显示的指定_id,不指定的话会默认生成一个值。 | ||
9 | + | ||
10 | +**2.“path”:“just name”废弃:** | ||
11 | + | ||
12 | + "productSkn": { | ||
13 | + "fields": { | ||
14 | + "productSkn": { | ||
15 | + "type": "string", | ||
16 | + "index": "not_analyzed", | ||
17 | + "doc_values": true, | ||
18 | + "fielddata": { | ||
19 | + "format": "doc_values" | ||
20 | + } | ||
21 | + }, | ||
22 | + "productSkn_ansj": { | ||
23 | + "type": "string", | ||
24 | + "store": false, | ||
25 | + "index_analyzer": "mmseg_complex", | ||
26 | + "search_analyzer": "mmseg_complex" | ||
27 | + } | ||
28 | + }, | ||
29 | + "type": "multi_field", | ||
30 | + "path": "just_name" | ||
31 | + } | ||
32 | +这种写法配置了 "path": “just_name”后如果想对productSkn_ansj进行查询,可以 | ||
33 | + | ||
34 | + { | ||
35 | + "match" : { | ||
36 | + “productSkn_ansj" : “xxx" | ||
37 | + } | ||
38 | + } | ||
39 | +但是在2.3.4版本中废除了 "path": “just_name”,查询productSkn_ansj的时候必须得full name,得这样写: | ||
40 | + | ||
41 | + { | ||
42 | + "match" : { | ||
43 | + “productSkn.productSkn_ansj" : “xxx" | ||
44 | + } | ||
45 | + } | ||
46 | + | ||
47 | +**3.index_analyzer废弃:** | ||
48 | + | ||
49 | +使用analyzer代替,如果index analyzer跟search analyzer一样的话不需要写search_analyzer,直接写一个analyzer就行了。 | ||
50 | + | ||
51 | +**4.doc_value fielddata变更:** | ||
52 | + | ||
53 | +not analyzer字段doc_value有效,默认为true | ||
54 | + | ||
55 | +analyzer字段fielddata有效,默认为true | ||
56 | + | ||
57 | +doc_value、fielddata都是为了聚合计算、排序、在脚本中访问字段值而引入的数据结构,是根据反向索引再次反向出来的一个正向索引,也就是文档到关键词的映射。 | ||
58 | + | ||
59 | +doc_value是落磁盘的,是预先构建的,也就是构建文档索引的时候。 | ||
60 | + | ||
61 | +fielddata是放内存的,是在一个字段在做聚合、排序、在脚本中访问的时候构建的(命中就不构建了)。 | ||
62 | + | ||
63 | +**5.Muticast Discovery变更:** | ||
64 | + | ||
65 | +Muticast Discovery默认不可用,需要安装相应的插件 | ||
66 | + | ||
67 | +**6.Filtered Query** | ||
68 | + | ||
69 | +这个已经 deprecated,在 2.x 中你还可以用。但是建议做如下修改 | ||
70 | + | ||
71 | + { | ||
72 | + "query": { | ||
73 | + "filtered": { | ||
74 | + "query": { | ||
75 | + ……. | ||
76 | + }, | ||
77 | + "filter": { | ||
78 | + ……. | ||
79 | + } | ||
80 | + } | ||
81 | + } | ||
82 | + } | ||
83 | +修改为 | ||
84 | + | ||
85 | + { | ||
86 | + "query": { | ||
87 | + "bool": { | ||
88 | + "must": { | ||
89 | + ……. | ||
90 | + }, | ||
91 | + "filter": { | ||
92 | + ……. | ||
93 | + } | ||
94 | + } | ||
95 | + } | ||
96 | + } | ||
97 | +把 query 和 filter 移到 bool 查询的 must 和 filter 参数之中。 | ||
98 | + | ||
99 | +**7.字段名不要有dot(点)** | ||
100 | + | ||
101 | +**8.optimize使用force merge接口代替** | ||
102 | + | ||
103 | +**9.启动es不能使用root,需要创建非root用户启动es** | ||
104 | + | ||
105 | +**10.multi field** | ||
106 | + | ||
107 | +1.4版本: | ||
108 | + | ||
109 | + "brandNameCn": { | ||
110 | + "fields": { | ||
111 | + "brandNameCn": { | ||
112 | + "type": "string", | ||
113 | + "store": false, | ||
114 | + "analyzer": "ik_complex", | ||
115 | + "search_analyzer": "ik_complex", | ||
116 | + "copy_to": ["searchField","searchField_ansj"] | ||
117 | + }, | ||
118 | + "brandNameCn_pinyin": { | ||
119 | + "type": "string", | ||
120 | + "store": false, | ||
121 | + "analyzer": "pinyin_analyzer", | ||
122 | + "search_analyzer": "standard" | ||
123 | + } | ||
124 | + }, | ||
125 | + "type": "multi_field" | ||
126 | + } | ||
127 | + | ||
128 | +2.3.4版本: | ||
129 | + | ||
130 | + { | ||
131 | + "brandNameCn": { | ||
132 | + "copy_to": [ | ||
133 | + "searchField", "searchField_ansj"], | ||
134 | + "analyzer": "ik_complex", | ||
135 | + "type": "string", | ||
136 | + "fields": { | ||
137 | + "brandNameCn_pinyin": { | ||
138 | + "search_analyzer": "standard", | ||
139 | + "analyzer": "pinyin_analyzer", | ||
140 | + "type": "string" | ||
141 | + } | ||
142 | + } | ||
143 | + } | ||
144 | + } | ||
145 | +**11.refresh_interval** | ||
146 | + | ||
147 | +1.4版本: refresh_interval=1 | ||
148 | + | ||
149 | +2.3.4版本: refresh_interval=1s |
-
Please register or login to post a comment