你只需要設置"index": "not_analyzed"
在球場上,你將能夠全額取回,未修改字段值在你的方面。
通常情況下,最好有一個版本的字段不被分析(用於分面),另一個版本是(用於搜索)。 "multi_field"
字段類型對此很有用。
因此,在這種情況下,我可以如下定義映射:
curl -XPUT "http://localhost:9200/test_index/" -d'
{
"mappings": {
"people": {
"properties": {
"full_name": {
"type": "multi_field",
"fields": {
"untouched": {
"type": "string",
"index": "not_analyzed"
},
"full_name": {
"type": "string"
}
}
}
}
}
}
}'
這裏,我們有兩個子領域。與父項名稱相同的項目將成爲默認項目,因此如果您在"full_name"
字段中進行搜索,則Elasticsearch實際上將使用"full_name.full_name"
。 "full_name.untouched"
會給你想要的方面結果。
所以接下來我添加了兩個文件:
curl -XPUT "http://localhost:9200/test_index/people/1" -d'
{
"full_name": "Jean-Paul Gautier"
}'
curl -XPUT "http://localhost:9200/test_index/people/2" -d'
{
"full_name": "Jean De La Fontaine"
}'
,然後我可以刻面的每個域,查看返回什麼:
curl -XPOST "http://localhost:9200/test_index/_search" -d'
{
"size": 0,
"facets": {
"name_terms": {
"terms": {
"field": "full_name"
}
},
"name_untouched": {
"terms": {
"field": "full_name.untouched",
"size": 100
}
}
}
}'
,我回來了以下內容:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0,
"hits": []
},
"facets": {
"name_terms": {
"_type": "terms",
"missing": 0,
"total": 7,
"other": 0,
"terms": [
{
"term": "jean",
"count": 2
},
{
"term": "paul",
"count": 1
},
{
"term": "la",
"count": 1
},
{
"term": "gautier",
"count": 1
},
{
"term": "fontaine",
"count": 1
},
{
"term": "de",
"count": 1
}
]
},
"name_untouched": {
"_type": "terms",
"missing": 0,
"total": 2,
"other": 0,
"terms": [
{
"term": "Jean-Paul Gautier",
"count": 1
},
{
"term": "Jean De La Fontaine",
"count": 1
}
]
}
}
}
正如您所看到的,分析的字段返回單個字,較小的標記(當您未指定分析r,則使用standard analyzer),並且未分析的子字段返回未修改的原始文本。
這是一個可運行的例子,你可以玩: http://sense.qbox.io/gist/7abc063e2611846011dd874648fd1b77450b19a5
經過一些困難,以更新我目前的映射,我成功了!感謝您的寶貴幫助。 – pierallard