带有过滤器的ElasticSearch function_score查询

乌迪

尝试创建一个搜索,该搜索将带回距某些地理位置约500m的位置结果。

我需要根据源中的位置是否为空来过滤此搜索的结果。

我尝试过这样的事情:

"filtered" : {
    "filter": {
        "missing" : { "field" : "location" }
    }
}

这是我得到的搜索JSON:

 {"query": {
        "function_score": {
            "query": {
                "bool": {
                    "must": [
                        {
                            "match": {"fieldA": "value"}
                        },
                        {
                            "match": { "fieldB": "value"}
                        }
                    ]
                }
            },
            "functions": [{
                    "gauss": {
                        "location": {
                            "origin": "'.$lat.','.$lon.'",
                            "scale": "500m",
                            "offset": "0km",
                            "decay": 0.33
                        }
                    }
                }]
        }
    }
}

我尝试将过滤器放置在查询中的不同位置,但对我而言不起作用,所以我知道我在构造查询的方式上犯了根本性的错误。将来,我想添加更多的评分逻辑和其他过滤器,但找不到此类查询的好例子。

我应该怎么做才能使其正常工作?

Duc Duong

您可以将过滤查询与geo_distance一起使用,以首先过滤出结果。您还可以在function_score中使用“权重”来显着提高“匹配”查询的距离:

{
   "query": {
      "function_score": {
         "query": {
            "filtered": {
               "query": {
                  "bool": {
                     "must": [
                        {
                           "match": {
                              "fieldA": "value"
                           }
                        },
                        {
                           "match": {
                              "fieldB": "value"
                           }
                        }
                     ]
                  }
               },
               "filter": {
                  "geo_distance" : {
                        "distance" : "500m",
                        "location" : "'.$lat.','.$lon.'"
                    }
               }
            }
         },
         "functions": [
            {
               "gauss": {
                  "location": {
                     "origin": "'.$lat.','.$lon.'",
                     "scale": "500m",
                     "offset": "0km",
                     "decay": 0.33
                  }
               },
               "weight": "3"
            }
         ]
      }
   }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法编译内联过滤器:<带有查询的Jsonpath>

在ElasticSearch中,排序如何与function_score交互?

More_like_this带有过滤器的查询

带有嵌套属性的过滤器和聚合的Elasticsearch DSL python查询

如何在Elasticsearch 5中向function_score查询添加过滤器

在ProxyAddresses上具有过滤器的Microsoft Graph API查询用户

如何查询表以获取在链接中没有记录的记录以及带有过滤器的记录

分页的SQL查询具有过滤器

在Elasticsearch中使用function_score时,是否在function_score对象内部或外部使用过滤器是否重要?

带有过滤器选项的Google图表MySQL查询百分比

elasticsearch-获得“ function_score”内的中间分数

具有过滤器的C#中的MongoDB Linq查询

通过ForeignKey外部引用对带有过滤器的子查询进行了汇总

返回页面时,带有过滤器搜索页面的Flutter不断从查询中添加相同的列表视图

带过滤器的ElasticSearch bool查询不适用于带有“-”的字段

elasticsearch,function_score SearchPhaseExecutionException

带有多个过滤器的Elasticsearch搜索查询

当执行参数化的N1QL查询时,Couchbase不使用带有过滤器的索引

PHP Elasticsearch,带有过滤器的布尔查询未获得任何结果

ElasticSearch 5.1 带有多重过滤器的过滤查询

elasticsearch function_score 返回意外分数

弹性搜索 更像这个带有过滤器的查询是添加结果

SQL查询返回匹配任何或所有过滤器但不超过过滤器的行

使用术语过滤器和 function_score 查询总是给出分数 0

ElasticSearch aggs with function_score

ES 7 - 使用带有过滤器的匹配查询

带有内部查询的Django过滤器?

带有多个过滤器的 Wordpress 查询帖子

Elasticsearch 7.14 constant_score 带有两个过滤器?