0
votes

I have a little question about elasticsearch.

I use the next mapping inside my table. (geonames table)

{
 "zoek": {
      "mappings": {
         "geo": {
            "properties": {
               "country": {
                  "type": "string"
               },
               "geonameid": {
                  "type": "string"
               },
               "locatie": {
                  "type": "geo_point"
               },
               "name": {
                  "type": "string"
               }
            }
         }
      }
   }
}

"locatie" is a geo_point mapping from array of double.

So searching for our local village "rhee" works fine:

GET /zoek/geo/_search
{
    "query": {
        "match": { "name": "rhee" }
    }
}

Answer:

{
   "took": 3,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 8.156567,
      "hits": [
         {
            "_index": "zoek",
            "_type": "geo",
            "_id": "4533",
            "_score": 8.156567,
            "_source": {
               "geonameid": "2748193",
               "name": "Rhee",
               "locatie": [
                  53.0325,
                  6.56667
               ],
               "country": "NL"
            }
         }
      ]
   }
}

-> now i want to query all places in a radius of 15 KM from "rhee" ( for instance )

GET /zoek/geo/_search
{
    "filtered" : {
        "query" : {
            "match": { "name": "rhee" }
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "15km",
                "locatie" : [ 53.0325, 6.56667 ]
                }
            }
        }
    }
}

The following exception is raised:

SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures

Parse Failure [No parser for element [filtered]]]

Also, this query:

get /zoek/geo/_search
{
  "query": {
    "filtered": {
      "filter": {
              "geo_distance": {
                "distance": "5km",
                "locatie": [ 53.0325, 6.56667 ]
                }
              }
      }
    }
  }
}

returns all fields instead of 5 km distance records.

Any suggestions?

Peace,

Digi

1

1 Answers

0
votes

Change this query

{
    "filtered" : {
        "query" : {
            "match" : {
                "name" : "rhee"
            }
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "15km",
                "locatie" : [53.0325, 6.56667]
            }
        }
    }
}

to

{
    "query" : {
        "filtered" : {
            "query" : {
                "match" : {
                    "name" : "rhee"
                }
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "15km",
                    "locatie" : [53.0325, 6.56667]
                }
            }
        }
    }
}

Outer query was missing.