如果您使用默认分析器(standard
) 如果它是空字符串,则没有任何内容可供分析。因此,您需要逐字索引该字段(未分析)。这是一个例子:
添加一个映射,该映射将索引未标记化的字段,如果您还需要索引字段的标记化副本,您可以使用多领域 http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/mapping-multi-field-type.html type.
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: ""
}
}
]
}
}