在Elasticsearch中将string的默认映射更改为“未分析”

在我的系统中,数据的插入总是通过logstash通过csv文件完成的。 我从来没有预先定义映射。 但是每当我input一个string时,总是需要进行analyzed ,结果就像是hello I am SinhaI分裂成了helloSinha 。 是否有反正我可以改变弹性search的默认/dynamic映射,使所有的string,而不论索引,不论types,都不被not analyzed ? 或者有没有办法在.conf文件中设置它? 说我的conf文件看起来像

 input { file { path => "/home/sagnik/work/logstash-1.4.2/bin/promosms_dec15.csv" type => "promosms_dec15" start_position => "beginning" sincedb_path => "/dev/null" } } filter { csv { columns => ["Comm_Plan","Queue_Booking","Order_Reference","Multi_Ordertype"] separator => "," } ruby { code => "event['Generation_Date'] = Date.parse(event['Generation_Date']);" } } output { elasticsearch { action => "index" host => "localhost" index => "promosms-%{+dd.MM.YYYY}" workers => 1 } } 

我希望所有的string都不要被not analyzed ,我不介意将它作为所有未来数据插入到elasticsearch的默认设置

您可以查询您的字段的.raw版本。 这是在Logstash 1.3.1中添加的:

我们提供的logstash索引模板为您索引的每个字段添加一个“.raw”字段。 这些“.raw”字段由logstash设置为“not_analyzed”,以便不进行分析或标记化 – 我们的原始值是原样使用的!

所以,如果你的领域被称为foo ,你会查询foo.raw返回not_analyzed (不分割分隔符)版本。

只需创build一个模板。 跑

 curl -XPUT localhost:9200/_template/template_1 -d '{ "template": "*", "settings": { "index.refresh_interval": "5s" }, "mappings": { "_default_": { "_all": { "enabled": true }, "dynamic_templates": [ { "string_fields": { "match": "*", "match_mapping_type": "string", "mapping": { "index": "not_analyzed", "omit_norms": true, "type": "string" } } } ], "properties": { "@version": { "type": "string", "index": "not_analyzed" }, "geoip": { "type": "object", "dynamic": true, "path": "full", "properties": { "location": { "type": "geo_point" } } } } } } }' 

从Logstash发行版(可能安装为/opt/logstash/lib/logstash/outputs/elasticsearch/elasticsearch-template.json)复制lib / logstash / outputs / elasticsearch / elasticsearch-template.json,并通过replace

 "dynamic_templates" : [ { "string_fields" : { "match" : "*", "match_mapping_type" : "string", "mapping" : { "type" : "string", "index" : "analyzed", "omit_norms" : true, "fields" : { "raw" : {"type": "string", "index" : "not_analyzed", "ignore_above" : 256} } } } } ], 

 "dynamic_templates" : [ { "string_fields" : { "match" : "*", "match_mapping_type" : "string", "mapping" : { "type" : "string", "index" : "not_analyzed", "omit_norms" : true } } } ], 

和点template为您输出插件到您的修改文件:

 output { elasticsearch { ... template => "/path/to/my-elasticsearch-template.json" } } 

您仍然可以覆盖特定字段的此默认值。

我认为更新映射是错误的方法来处理报告的目的字段。 迟早你可能希望能够search令牌的领域。 如果您将该字段更新为“not_analyze”,并且希望从值“foo bar”searchfoo,那么您将无法做到这一点。

更优雅的解决scheme是使用kibana聚合filter而不是术语。 像下面的东西将search条款ivr04和ivr02。 所以在你的情况下,你可以有一个filter“你好,我是辛哈”。 希望这可以帮助。

在这里输入图像说明