如果您存储了源代码(这是默认设置),则可以使用脚本过滤器
它应该是这样的:
$ curl -XPUT localhost:9200/index/type/1 -d '{"foo": "bar"}'$ curl -XPUT localhost:9200/index/type/2 -d '{"foo": "bar baz"}'$ curl -XPOST localhost:9200/index/type/_search?pretty=true -d '{"filter": { "script": { "script": "_source.foo == "bar"" }}}'{ "took" : 2, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 1.0, "hits" : [ { "_index" : "index", "_type" : "type", "_id" : "1", "_score" : 1.0, "_source" : {"foo": "bar"} } ] }}编辑 :我认为值得一提的是,“
not_analyzed”映射应该是更快的方法。但是,如果您想同时对该字段进行完全匹配和部分匹配,则可以看到两个选项:使用脚本或对数据进行两次索引(一次分析,一次不分析)。



