gpt4 book ai didi

java - 如何将地理距离过滤器与 boolean 术语查询合并

转载 作者:行者123 更新时间:2023-12-01 10:01:04 24 4
gpt4 key购买 nike

如何使用 Elasticsearch 1.6/1.7 版本地理距离过滤器和 boolean 术语查询,如下所示。这里如何合并这两个查询

原始查询:

{
"query": {
"bool": {
"must": [
{
"term": {
"categories": "tv"
}
}
],
"should": [
{
"term": {
"subCategory": "led"
}
}
],
"minimum_should_match": 1,
"boost": 2
}
}
}

我想搜索距离为 10 英里且具有上述 bool 查询的产品

{
"filtered": {
"filter": {
"geo_distance": {
"distance": "10km",
"sellerInfoES.address.sellerLocation": "28.628978,77.21971479999999"
}
}
}
}

谢谢瓦尔!查询正在运行,我没有收到任何查询解析错误。但是,此地理查询未返回距离范围结果。我使用 Elasticsearch 1.6 并将 sellerLocation 存储为 geo_point.Mapping:

{
"SellerInfoES": {
"type": "nested",
"properties": {
"sellerLocation": {
"type": "geo_point"
}
}
}
}

此 geo_query 不起作用

{
"geo_distance": {
"distance": "100km",
"sellerLocation": {
"lat": 28.628978,
"lon": 77.21971479999999
}
}
}

最佳答案

您可以像这样组合查询/过滤器:

{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"categories": "tv"
}
},
{
"nested": {
"path": "sellerInfoES",
"filter": {
"geo_distance": {
"distance": "10km",
"sellerInfoES.sellerLocation": {
"lat": "28.628978",
"lon":"77.21971479999999"
}
}
}
}
}
],
"should": [
{
"term": {
"subCategory": "led"
}
}
],
"minimum_should_match": 1,
"boost": 2
}
}
}
}
}

关于java - 如何将地理距离过滤器与 boolean 术语查询合并,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36805014/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com