【发布时间】:2015-12-08 23:31:28
【问题描述】:
我在 ES 中使用建议 api 并完成。我的实现有效(下面的代码),但我想在查询中搜索多个单词。在下面的示例中,如果我查询搜索“word”,它会找到“wordpress”并输出“Found”。我想要完成的是使用“word blog magazine”之类的东西进行查询,这些都是标签并且输出为“Found”。任何帮助,将不胜感激!
映射:
curl -XPUT "http://localhost:9200/test_index/" -d'
{
"mappings": {
"product": {
"properties": {
"description": {
"type": "string"
},
"tags": {
"type": "string"
},
"title": {
"type": "string"
},
"tag_suggest": {
"type": "completion",
"index_analyzer": "simple",
"search_analyzer": "simple",
"payloads": false
}
}
}
}
}'
添加文档:
curl -XPUT "http://localhost:9200/test_index/product/1" -d'
{
"title": "Product1",
"description": "Product1 Description",
"tags": [
"blog",
"magazine",
"responsive",
"two columns",
"wordpress"
],
"tag_suggest": {
"input": [
"blog",
"magazine",
"responsive",
"two columns",
"wordpress"
],
"output": "Found"
}
}'
_建议查询:
curl -XPOST "http://localhost:9200/test_index/_suggest" -d'
{
"product_suggest":{
"text":"word",
"completion": {
"field" : "tag_suggest"
}
}
}'
The results are as we would expect:
{
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"product_suggest": [
{
"text": "word",
"offset": 0,
"length": 4,
"options": [
{
"text": "Found",
"score": 1
},
]
}
]
}
【问题讨论】:
-
您愿意使用 ngram 解决方案而不是完成建议吗?
-
实际上我之前用模糊的方式实现了边缘 gram,但我的分数都搞砸了,建议使用建议 api 来更快地查询大量数据。你对两者有何看法?对我来说,一个关键要求是用空格分隔多个搜索
-
最后一部分很容易使用 ngram 解决方案。不过,不确定得分。而且我不确定是否要做一个多学期的完成建议。我得调查一下。我假设您想要 OR 搜索,而不是 AND,对吗?
-
你指的是哪一部分?我会给你一个例子来帮助解释我的要求。我有一个包含第一个、中间、最后一个 dob 字段的用户类型。我想做一个搜索,一个查询可以处理任何数量的字段的任何顺序。例如:last、first、dob、middle 或 first、dob 或 just dob 并返回用户。前端将是一个用于输入信息的文本块。非常感谢您的帮助!
标签: search elasticsearch autocomplete search-suggestion