0

I want to make a query with a keyword and show only the posts 150km around me within the queried keyword my query below is working but shows all the posts

{
    "query": {
        "regexp": {
            "title": {
                "value": ".*h.*",
                "flags": "ALL",
                "max_determinized_states": 10000,
                "rewrite": "constant_score"
            }
        }
    },
     "sort": [{
        "date": {
            "order": "desc"
        }
    }]
}

but when I add the filter query like follows I am receiving parsing error

"filter": {
              "geo_distance": {
                   "distance": "150km",
                        "location": {
                         "lat": \(latitude),
                         "lon": \(longitude)
                         }
                   }
          }

Any one can help please

1 Answers1

0

Here is the query you should be using, which combines both the regexp query and the geo_distance query using a bool/filter query:

{
  "query": {
    "bool": {
      "filter": [
        {
          "geo_distance": {
            "distance": "150km",
            "location": {
               "lat": \(latitude),
               "lon": \(longitude)
            }
          }
        },
        {
          "regexp": {
            "title": {
              "value": ".*h.*",
              "flags": "ALL",
              "max_determinized_states": 10000,
              "rewrite": "constant_score"
            }
          }
        }
      ]
    }
  },
  "sort": [
    {
      "date": {
        "order": "desc"
      }
    }
  ]
}
Val
  • 207,596
  • 13
  • 358
  • 360
  • please can you help with this question https://stackoverflow.com/questions/60991499/elasticsearch-autocomplete-suggester?noredirect=1#comment107913286_60991499 –  Apr 03 '20 at 08:46