give preference to perfect match
I'm new to elastic.
I'm using elastic search to search on the title field of documents stored in my database. More info: "title" field - type "String"/indexed and "title.unanalyzed" field - type "String"/unindexed
.
I want the document whose title has a perfect match with the query to occur at the top of the search results while for all others, I want the them to be sorted in decending order of score. I guess giving a score of 1.1 to documents with exactly matched title will help as elastic scores between 0 and 1 for analyzed fields. My current query:
query: {
term: {
"title.unanalyzed": "some_title"
},
multi_match: {
query: "some_title",
type: "most_fields",
fields: ["title", "other"]
}
}
gives an error: failed to parse search source. expected field name but got [START_OBJECT]
failed to parse search source. expected field name but got [START_OBJECT]
. Need help, thanks!
试试这个:
{
"query": {
"bool": {
"should": [
{
"term": {
"title.unanalyzed": "some_title"
}
},
{
"multi_match": {
"query": "some_title",
"type": "most_fields",
"fields": [
"title",
"other"
]
}
}
]
}
}
}
链接地址: http://www.djcxy.com/p/60138.html
上一篇: 弹性搜索执行缓慢
下一篇: 优先选择完美匹配