由于您没有发布代码,因此很难判断出了什么问题,但映射中的 "index": "not_analyzed" 是处理此问题的正确方法。
这是一个简单的工作示例。首先我创建一个使用"index": "not_analyzed"的映射:
PUT /test_index
{
"mappings": {
"doc": {
"properties": {
"name":{
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
然后添加几个文档进行测试
POST /test_index/doc/_bulk
{"index":{"_id":1}}
{"name":"XYZ Company Solutions"}
{"index":{"_id":2}}
{"name":"Another Company"}
现在我可以通过简单的term query 得到我想要的文档:
POST /test_index/doc/_search
{
"query": {
"term": {
"name": {
"value": "XYZ Company Solutions"
}
}
}
}
...
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "1",
"_score": 1,
"_source": {
"name": "XYZ Company Solutions"
}
}
]
}
}
term filter 甚至 match query 在这种情况下也可以使用。
这是我用来测试它的代码:
http://sense.qbox.io/gist/90fcc7f7a88d58f098c50d5aaf0315fdf06e9e9a