#ignore_above #长度超过ignore_above设置的字符串将不会被索引或存储(个人认为会存储,但不会为该字段建立索引,也就是该字段不能被检索)。 对于字符串数组,ignore_above将分别应用于每个数组元素,并且不会索引或存储比ignore_above更长的字符串元素。 PUT w1 { "mappings": { "doc":{ "properties":{ "t1":{ "type":"keyword", "ignore_above": 5 }, "t2":{ "type":"keyword", "ignore_above": 10 } } } } } PUT w1/doc/1 { "t1":"elk", "t2":"elasticsearch" } GET w1/doc/_search { "query":{ "term": { "t1": "elk" } } } GET w1/doc/_search { "query": { "term": { "t2": "elasticsearch" } } } #对于值ignore_above是字符数,但Lucene的字节数为单位。如果您使用带有许多非ASCII字符的UTF-8文本,您可能需要设置限制,32766 / 4 = 8191因为UTF-8字符最多可占用4个字节。 DELETE /w1 # 那么如果字符串的类型是text时能用ignore_above吗,答案是能,但要特殊设置: PUT w2 { "mappings": { "doc":{ "properties":{ "t1":{ "type":"keyword", "ignore_above":5 }, "t2":{ "type":"text", "fields":{ "keyword":{ "type":"keyword", "ignore_above": 10 } } } } } } } PUT w2/doc/1 { "t1":"beautiful", "t2":"beautiful girl" } GET w2/doc/_search { "query": { "term": { "t1": { "value": "beautiful" } } } } GET w2/doc/_search { "query": { "term": { "t2": "beautiful" } } } DELETE /w2 #当使用create index API时,作为create index调用的一部分定义的设置/映射将优先于模板中定义的任何匹配设置/映射。 PUT _template/2019 { "index_patterns": ["20*", "product1*"], "settings":{ "number_of_shards": 2, "number_of_replicas": 1 }, "mappings":{ "doc":{ "properties":{ "ip":{ "type":"keyword" }, "method":{ "type": "keyword" } } } } } #①,index_patterns是索引模式,指当创建以20和product1开头的索引时,使用该索引模板。注意,在elasticsearch的6.x版本中,索引模板模式index_patterns取代原来的template。 #②,在settings设置中,我们自定义为该索引分配3个主分片。复制分片不变。 #③,mappings中指定映射关系。 GET _template/2019 GET /_template/20* GET /_template/2019,2010 #我们可以查看所有可用的模板列表: GET /_template #查询模板是否存在 HEAD _template/2019 #注意,返回是以HTTP的状态表示模板是否存在,200表示存在,404表示不存在 #使用模板 PUT 201901/doc/1 { "ip": "127.0.0.1", "method":"GET" } PUT 201902/doc/2 { "ip":"192.168.1.1", "method":"POST" } PUT product1_log/doc/1 { "ip":"127.0.0.1", "method":"GET" } HEAD 2019 HEAD product1_log GET product1_log PUT _template/2018_2 { "index_patterns": ["201802*"], "order":1, "settings":{ "number_of_shards": 3 } } PUT 2018010201/doc/1 { "method": "POST" } GET 2018010201 #案例使用场景 #可以看到20180201索引应用了order参数为1的索引模板。这在某些情况下非常有效,比如我们预料到2018年2月份的日志将会暴增,而其他月份不变,所以我们通过上述创建多个模板来完成索引创建,2月份每天的索引的主分片都多一片,过了2月,恢复正常。 DELETE 20190101 DELETE 20190102 DELETE product1_log DELETE product1_log DELETE _template/2019 DELETE 2019* #当索引一个文档的时候,文档会被存储到一个主分片中。那么,elasticsearch如何知道一个文档应该存放到哪个分片中呢? #首先这肯定不是随机的,否则在检索文档时就不知道该从哪去寻找它了。实际上这个过程是根据下面公式决定的: #shard = hash(routing) % number_of_primary_shards #routing #所有的文档 API( get 、 index 、 delete 、 bulk 、 update 以及 mget )都接受一个叫做 routing 的路由参数 ,通过这个参数我们可以自定义文档到分片的映射。一个自定义的路由参数可以用来确保所有相关的文档——例如所有属于同一个用户的文档——都被存储到同一个分片中。 PUT r1/doc/1?routing=user1 { "title":"论母猪的产前保养" } PUT r1/doc/2?routing=user1 { "title":"论母猪的产后护理" } GET r1/doc/1?routing=user1 #通过路由属性进行查询 GET r1/doc/_search { "query": { "terms": { "_routing":["user1"] } } } DELETE r1/doc/1 #由上例可见,不提供路由,无法删除文档。 DELETE r1/doc/1?routing=user1 DELETE /r1 PUT r2/doc/1?routing=user1 { "title":"母猪产前保养重点在多喂饲料,辅以人工按摩" } PUT r2/doc/2?routing=user2 { "title":"母猪产后护理重点在母子隔离喂养" } GET r2/doc/_search?routing=user1,user2 { "query": { "match": { "title": "母猪" } } } DELETE /r2 #创建数据的时候忘了路由值配置怎么办? PUT r3/doc/1?routing=u1 { "title":"小猪仔真可爱" } #没有指定路由,数据就可能会放到不同的分片 PUT r3/doc/2 { "title":"可爱可爱一盘菜" } GET r3/doc/_search { "query": { "terms": { "_routing":["u1"] } } } GET r3/doc/_search DELETE /r3 #答案就是我们在创建索引的时候显式的指定必须要有路由才能进行CURD操作 PUT r4 { "mappings": { "doc":{ "_routing":{ "required": true } } } } DELETE /r4 #下面是elasticsearch7.0推荐的写法,我使用的是6.7.0所以没有测试 PUT my_index2 { "mappings": { "_usting":{ "required": true } } }
版权声明:除特别注明外,本站所有文章均为王晨曦个人站点原创
转载请注明:出处来自王晨曦个人站点 » elasticsearch研习(七)
Cialis Generique Site Fiable
Cialis Con Red Bull
Zithromax Annostus
Burpropionxl Vs Vyvance
http://buypriligyhop.com/ - priligy en france
Prostate Gland Infection And Cephalexin
KCD Red Electrical Rocker Switch Beckhoff Servo Motor ルイヴィトン財布コピー激安代引き
Ice Platinum ルイヴィトン財布コピー激安代引き Convex Oil Flower Rectangle Shell Mosaic Tiles
ルイヴィトン財布コピー Universal Waterproof Distribution Box Vinyl Lamination Machine
Even And Odd Harmonic Filters ルイヴィトン財布コピー Portable Otorhinolaryngologic Endoscopic Camera
ルイヴィトンコピー財布 Brushed Gold Bathroom Mixer Countersunk Concrete Anchors
ルイヴィトン財布コピー 4 Way Black Pipe Fitting Precision Casting Auto Parts
Office Rubber Band Mercedes Benz Brake Valve ルイヴィトン財布コピー激安代引き
Drone Professional 4k ルイヴィトンコピー財布 Sinotruk Howo 6 Wheelers 4*2 Truck Head Prime Mover Euro Iv 340hp
ルイヴィトンコピー財布 Transported From China To Russia mini Micro load cell 8
ヴィトン財布コピー Copper Pendant Light Loving Strawberry Pattern Earrings With Bow
Compact Electric Linear Actuator Double Pass Copper Column ルイヴィトン財布スーパーコピー
Cleaning Rag Circuit Breaker Earthing Switch ヴィトン財布コピー
China Cbd Vape Factory ルイヴィトン財布コピー Injection molded PP GF30 glass filled PP molded parts
ルイヴィトン財布コピー激安代引き 72 Eggs Incubator Fish Imitation