Unknown key for a START_OBJECT in [bool] in elastic search

dkp1997 picture dkp1997 · Dec 12, 2017 · Viewed 9.5k times · Source

Elasticsearch is giving this error like Unknown key for a START_OBJECT in [bool] in Elasticsearch.

My query is as below: Updated

var searchParams = {
  index: 'offers',
  body:{
    query:{
    bool : {
      must : {
        query: {
            multi_match: {
                  query: query,
                  fields:['title','subTitle','address','description','tags','shopName'],
                  fuzziness : 'AUTO'
            }
        }
      },
      filter : {
            geo_distance : {
                distance : radius,
                location : {
                    lat : latitude,
                    lon : longitude
                }
            }
        }
    }}},
  filter_path :'hits.hits._source',
  pretty:'true'
};

Can anyone tell me how to mix this both geo and fuzzy search query in elastic search?

Answer

Val picture Val · Dec 12, 2017

The body should look like this (you're missing the query section):

  body:{
   query: {        <--- add this
    bool : {
      must : {
          multi_match: {
                query: query,
                fields:['title','subTitle','address','description','tags','shopName'],
                fuzziness : 'AUTO'
          }
      },
      filter : {
            geo_distance : {
                distance : radius,
                location : {
                    lat : latitude,
                    lon : longitude
                }
            }
        }
    }}},