作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含条目的数据库
title: This is my awesome title
abstract: A more detailed descriptions of what [...]
我想构建一个与上述文档相匹配的 Elasticsearch 查询,例如,
awe detai
在单词中:具有多个搜索词的 multi_match phrase_prefix 查询。 (这旨在用作“键入时搜索”功能。)
我知道如何组合使用 multi_match 和 phrase_prefix,但我不清楚如何针对多个搜索词执行此操作。
有什么提示吗?
最佳答案
好吧,有几种方法可以做到这一点
POST stack/autocomplete/1
{
"title": "This is my awesome title",
"abstract": "A more detailed descriptions of what"
}
然后您可以使用带星号的查询字符串进行搜索,但这里的问题是您需要在查询中附加星号
POST stack/autocomplete/_search
{
"query": {
"query_string": {
"fields": [
"title",
"abstract"
],
"query": "awe* detai*"
}
}
}
如果你想匹配用户查询那么你可以这样使用
POST stack/autocomplete/_search
{
"query": {
"multi_match": {
"fields": [
"title",
"abstract"
],
"query": "awesome tit",
"type": "phrase_prefix"
}
}
}
要考虑的另一种选择是使用 nGram带有查询字符串,因此您无需修改用户查询“awe* detai*”
关于Elasticsearch:具有多个搜索词的 multi_match phrase_prefix 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35584338/
我有一个包含条目的数据库 title: This is my awesome title abstract: A more detailed descriptions of what [...] 我想
根据多匹配查询 (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query
我是一名优秀的程序员,十分优秀!