【发布时间】:2018-02-23 20:02:54
【问题描述】:
我有一个 ElsaticSearch 索引,用于保存某些数据。索引中的每个文档在嵌套文档中都有一个名为 file_name 的字段。所以一个文档看起来像
{
...
"file_data":{
"file_name": "sample_filename_acp24_20180223_1222.json"
}
...
}
如果我搜索sample、filename、acp24 和20180223 等,我希望我的搜索返回上述文档。
到目前为止,我尝试了以下分析器和全文搜索查询。但如果我搜索acp24、20180223,它仍然不会返回上述文档。
索引映射
{
"index_name": {
"mappings": {
"type": {
"properties": {
"file_data": {
"type": "nested",
"properties": {
"file_name": {
"type": "text",
"analyzer": "keyword_analyzer",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
}
分析器
{
"analysis": {
"analyzer": {
"keyword_analyzer":{
"type": "pattern",
"pattern":"\\W|_",
"lowercase": true
}
}
}
}
搜索查询
{
"query": {
"match_phrase_prefix": {
"_all": {
"query": "20180223",
"analyzer": "keyword_analyzer"
}
}
}
}
非常感谢任何有关如何实现这一目标的帮助。我花了这么多小时,仍然找不到解决方案。
【问题讨论】:
标签: elasticsearch full-text-search