如果您使用默认的分析器(
standard),则没有任何内容可以分析它是否为空字符串。因此,您需要逐字索引字段(未分析)。这是一个例子:
添加一个映射,该映射将为未标记的字段建立索引,如果您还需要索引的字段的标记化副本,则可以使用“
多字段”类型。
PUT http://localhost:9200/test/_mapping/demo{ "demo": { "properties": { "_content": { "type": "string", "index": "not_analyzed" } } }}接下来,索引几个文档。
/POST http://localhost:9200/test/demo/1/{ "_content": ""}/POST http://localhost:9200/test/demo/2{ "_content": "some content"}执行搜索:
POST http://localhost:9200/test/demo/_search{ "query": { "filtered": { "filter": { "term": { "_content": "" } } } }}返回带有空字符串的文档。
{ took: 2, timed_out: false, _shards: { total: 5, successful: 5, failed: 0 }, hits: { total: 1, max_score: 0.30685282, hits: [ { _index: test, _type: demo, _id: 1, _score: 0.30685282, _source: { _content: "" } } ] }}


