Nested Solr spatial query using JSON request API

Viewed 140

How to combine a nested query with a spatial filter in Apache Solr? This is a simplified nested query which should be combined with a spatial filter:

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

It doesn't work this way:

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"
        }
      ]
    }
  }
}'

What's the correct query syntax to combine spatial filters with nested queries?

Note: The original query is more complex and the filter can't be at the same level as "query" because it needs to be part of one "must" query conditions but must not be applied to another condition.

1 Answers

The solution is:

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

The documentation describes examples how to transform query strings to JSON objects: https://solr.apache.org/guide/8_0/json-query-dsl.html

Finally, the query looks like:

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.)"
      ]
    }
  }
}'
Related