【问题标题】:Nested Solr spatial query using JSON request API使用 JSON 请求 API 的嵌套 Solr 空间查询
【发布时间】:2021-12-21 03:40:43
【问题描述】:

如何在 Apache Solr 中将嵌套查询与空间过滤器结合使用?这是一个简化的嵌套查询,应该与空间过滤器结合使用:

curl "http://localhost:8983/solr/corename/query" -d '{
  "query":{
    "bool":{
      "must":[
        "type:product",
        "product.siteid:(1.)",
      ]
    }
  }
}'

这样不行:

curl "http://localhost:8983/solr/corename/query" -d '{
  "query":{
    "bool":{
      "must":[
        "type:product",
        "product.siteid:(1.)",
        {
          "filter":"{!bbox sfield=index.supplierloc}",
          "pt":"52.5,10",
          "d":"115"
        }
      ]
    }
  }
}'

将空间过滤器与嵌套查询相结合的正确查询语法是什么?

注意:原始查询更复杂,过滤器不能与“查询”处于同一级别,因为它需要是一个“必须”查询条件的一部分,但不能应用于另一个条件。

【问题讨论】:

  • 我不确定您是否可以使用 BoolQParser 做到这一点。您可以尝试在params 中指定fq,例如:fq: "(type:product) AND (product.siteid:(1.)) AND ({!bbox sfield=index.supplierloc})",以及ptd(但这不是很JSONesque..)。

标签: json solr spatial


【解决方案1】:

解决办法是:

"bbox":{
    "sfield":"index.supplierloc",
    "pt":"52.5,10",
    "d":115
}

文档描述了如何将查询字符串转换为 JSON 对象的示例: https://solr.apache.org/guide/8_0/json-query-dsl.html

最后,查询如下:

curl "http://localhost:8983/solr/aimeos/query" -d '{
  "query":{
    "bool":{
      "must":[{
        "bbox": {
          "sfield":"index.supplierloc",
          "pt":"52.5,10",
          "d":"115"
        }},
        "type:product",
        "product.siteid:(1.)"
      ]
    }
  }
}'

【讨论】:

    猜你喜欢
    • 2021-12-20
    • 2022-01-16
    • 2016-05-24
    • 1970-01-01
    • 2017-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多