【发布时间】:2014-10-02 08:49:32
【问题描述】:
我想使用 elasticsearch 进行多词搜索,其中所有字段都使用分配的分析器在文档中进行检查。
所以如果我有一个映射:
{
"settings": {
"analysis": {
"analyzer": {
"folding": {
"tokenizer": "standard",
"filter": [ "lowercase", "asciifolding" ]
}
}
}
},
"mappings" : {
"typeName" :{
"date_detection": false,
"properties" : {
"stringfield" : {
"type" : "string",
"index" : "folding"
},
"numberfield" : {
"type" : "multi_field",
"fields" : {
"numberfield" : {"type" : "double"},
"untouched" : {"type" : "string", "index" : "not_analyzed"}
}
},
"datefield" : {
"type" : "multi_field",
"fields" : {
"datefield" : {"type" : "date", "format": "dd/MM/yyyy||yyyy-MM-dd"},
"untouched" : {"type" : "string", "index" : "not_analyzed"}
}
}
}
}
}
}
如您所见,我有不同类型的字段,但我确实知道结构。 我想要做的是用一个字符串开始搜索,以使用分析器检查所有字段。
例如,如果查询字符串是:
John Smith 2014-10-02 300.00
我想在所有字段中搜索“John”、“Smith”、“2014-10-02”和“300.00”,同时计算相关性得分。更好的解决方案是在单个文档中包含更多字段匹配项。
到目前为止,我能够使用 multi_field 搜索所有字段,但在这种情况下,我无法解析 300.00,因为 300 存储在 multi_field 的字符串部分中。 如果我在“_all”字段中搜索,则没有使用分析器。
我应该如何修改我的映射或查询以进行多词搜索,其中日期和数字在多词查询字符串中被识别? 现在,当我进行搜索时,会发生错误,因为无法将整个字符串解析为数字或日期。如果我使用 multi_search 的字符串表示,那么 300.00 将不会是结果,因为字符串表示是 300。
(我想要的是类似于 google 搜索,在多词查询中可以识别日期、数字和字符串)
有什么想法吗?
谢谢!
【问题讨论】:
标签: elasticsearch