【发布时间】:2016-05-07 05:23:06
【问题描述】:
在我的一些文档中,我有 $ 或 £ 符号。我想搜索 £ 并检索包含该符号的文档。我经历了the documentation,但我遇到了一些认知失调。
# Delete the `my_index` index
DELETE /my_index
# Create a custom analyzer
PUT /my_index
{
"settings": {
"analysis": {
"char_filter": {
"&_to_and": {
"type": "mapping",
"mappings": [
"&=> and ",
"$=> dollar "
]
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"char_filter": [
"html_strip",
"&_to_and"
],
"tokenizer": "standard",
"filter": [
"lowercase"
]
}
}
}
}
}
正如文档所述,这将返回“the”、“quick”、“and”、“brown”、“fox”:
# Test out the new analyzer
GET /my_index/_analyze?analyzer=my_analyzer&text=The%20quick%20%26%20brown%20fox
这将返回“the”、“quick”、“dollar”、“brown”、“fox”
GET /my_index/_analyze?analyzer=my_analyzer&text=The%20quick%20%24%20brown%20fox
添加一些记录:
PUT /my_index/test/1
{
"title": "The quick & fast fox"
}
PUT /my_index/test/1
{
"title": "The daft fox owes me $100"
}
我会想如果我搜索“美元”,我会得到结果吗?相反,我没有得到任何结果:
GET /my_index/test/_search
{ "query": {
"simple_query_string": {
"query": "dollar"
}
}
}
或者甚至在分析器中使用“$”:
GET /my_index/test/_search
{ "query": {
"query_string": {
"query": "dollar10",
"analyzer": "my_analyzer"
}
}
}
【问题讨论】:
-
你能用词转换器检查实际分析的数据吗:elastic.co/guide/en/elasticsearch/reference/current/…
标签: elasticsearch