【发布时间】:2016-02-19 15:16:59
【问题描述】:
当我们传递包含特殊字符的查询时,Elastic Search 会拆分文本。 例如。如果我们在查询中通过“test-test”,我们如何让 Elastic Search 将其视为一个单词而不是将其拆分。
我们正在搜索的领域使用的分析仪:
"text_search_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 15
},
"standard_stop_filter": {
"type": "stop",
"stopwords": "_english_"
}
},
"analyzer": {
"text_search_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding",
"text_search_filter"
]
}
}
也是搜索的查询:
"query": {
"multi_match": {
"query": "test-test",
"type": "cross_fields",
"fields": [
"FIELD_NAME"
],
}
}
{
"tokens": [
{
"token": "'",
"start_offset": 0,
"end_offset": 11,
"type": "word",
"position": 1
},
{
"token": "'t",
"start_offset": 0,
"end_offset": 11,
"type": "word",
"position": 1
},
{
"token": "'te",
"start_offset": 0,
"end_offset": 11,
"type": "word",
"position": 1
},
{
"token": "'tes",
"start_offset": 0,
"end_offset": 11,
"type": "word",
"position": 1
},
{
"token": "'test",
"start_offset": 0,
"end_offset": 11,
"type": "word",
"position": 1
},
{
"token": "'test-",
"start_offset": 0,
"end_offset": 11,
"type": "word",
"position": 1
},
{
"token": "'test-t",
"start_offset": 0,
"end_offset": 11,
"type": "word",
"position": 1
},
{
"token": "'test-te",
"start_offset": 0,
"end_offset": 11,
"type": "word",
"position": 1
},
{
"token": "'test-tes",
"start_offset": 0,
"end_offset": 11,
"type": "word",
"position": 1
},
{
"token": "'test-test",
"start_offset": 0,
"end_offset": 11,
"type": "word",
"position": 1
},
{
"token": "'test-test'",
"start_offset": 0,
"end_offset": 11,
"type": "word",
"position": 1
}
]
}
【问题讨论】:
-
您的用例是什么?你的
mapping是什么?因为有不同的方法可以实现这一点 -
更新了使用的分析器和用于搜索的查询。我们可以看到使用分析器创建了一个令牌“test-test”。
-
curl -XGET 'localhost:9200/your_index_name/_analyze?analyzer=test_search_analyzer' -d 'test-test'的输出是什么 -
您在输出中看到标记“test-test”吗?
-
您确定您搜索的所有字段都应用了 test_search_analyzer 吗?因为 test-test 是令牌之一,它应该匹配。你没有使用不同的
search_analyzer对吗?
标签: elasticsearch lucene