您需要在"email"
字段輸入"index":"not_analyzed"
。這樣,查詢的唯一條款是已存儲到該字段的確切值(與standard analyzer的情況相反,如果沒有列出分析儀,則爲默認值)。
爲了說明這一點,我設置了不分析email
領域一個簡單的映射,並增加了兩個簡單的文檔:
DELETE /test_index
PUT /test_index
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"doc": {
"properties": {
"email": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
PUT /test_index/doc/1
{"email": "[email protected]"}
PUT /test_index/doc/2
{"email": "[email protected]"}
現在你匹配查詢將只返回精確匹配查詢的文檔:
POST /test_index/_search
{
"query": {
"match" : {
"email" : "[email protected]"
}
}
}
...
{
"took": 2,
"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": {
"email": "[email protected]"
}
}
]
}
}
這裏是我使用的代碼:
http://sense.qbox.io/gist/12763f63f2a75bf30ff956c25097b5955074508a
PS:您實際上可能想要的是term query甚至term filter,因爲您不希望對查詢文本進行任何分析。所以也許是這樣的:
POST /test_index/_search
{
"query": {
"constant_score": {
"filter": {
"term": {
"email": "[email protected]"
}
}
}
}
}
是否可能將它添加到所有索引? – placplacboom 2015-02-10 12:10:41
您可以設置如下所示的內容:https://github.com/elasticsearch/elasticsearch/issues/8015,使用[copy_to](http://www.elasticsearch.org/guide/en/elasticsearch/reference /current/mapping-core-types.html#copy-to)。我無法使用''_all「'字段使其工作。 – 2015-02-10 17:12:59
非常感謝! – placplacboom 2015-02-10 17:13:50