我有一些PageDocument
要根据标题搜索的,但不包括PageDocument
以某些特定文本开头的路径的。分析该字段。我想要一些模糊性来帮助用户解决拼写错误。我需要能够进行部分匹配,所以some
匹配some text
和this is some text
。
如果我使用以下查询,由于tf-idf,我没有得到完全匹配的结果作为第一个结果
{
"size": 20,
"query": {
"bool": {
"must": [
{
"match": {
"title": {
"query": "myterm",
"fuzziness": 1
}
}
}
],
"must_not": [
{
"wildcard": {
"path": {
"value": "/test/*"
}
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,我在处添加了not_analyzed
title字段的版本,title.not_analyzed
并尝试使用来添加函数得分以增加完全匹配的权重term
。
{
"query": {
"function_score": {
"functions": [
{
"weight": 2,
"filter": {
"fquery": {
"query": {
"term": {
"title.not_analyzed": {
"value": "myterm"
}
}
}
}
}
}
],
"query": {
"bool": {
"must": [
{
"match": {
"title": {
"query": "myterm",
"fuzziness": 1
}
}
}
],
"must_not": [
{
"wildcard": {
"path": {
"value": "/path/*"
}
}
}
]
}
},
"boost_mode": "multiply"
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这给了我相同的结果。我如何才能首先获得完全匹配的结果?
我们加入的组合找到了解决这个should
和boost
。
{
"size": 20,
"query": {
"bool": {
"must": [
{
"match": {
"title": {
"query": "myterm",
"fuzziness": 1
}
}
}
],
"must_not": [
{
"wildcard": {
"path": {
"value": "/path/*"
}
}
}
],
"should": [
{
"term": {
"title": {
"value": "myterm",
"boost": 10
}
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1740 次 |
最近记录: |