Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am tried to create search query with a values in 15m radios and between 3 weeks. I tried to execute this query:

"query": {
"bool": {
  "must": {
    "match_all": {}
  }
, "filter": [
  {
    "geo_distance": {
     
      "distance": "1000km",
      "geoLocation": {
        "lat": 31.966467334184614,
        "lon": 35.83242623178664
      }
    }
    ,
   "range": {
      "map_date": {
        "gte": "now-3w/w",
        "lte": "now/w"
      }
    }
    
  }
]
}}

My date filed is: map_date and my geo point filed is geoLocation

I get this response :

{
  "error" : {
    "root_cause" : [
      {
        "type" : "parsing_exception",
        "reason" : "[geo_distance] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
        "line" : 18,
        "col" : 8
      }
    ],
    "type" : "x_content_parse_exception",
    "reason" : "[18:8] [bool] failed to parse field [filter]",
    "caused_by" : {
      "type" : "parsing_exception",
      "reason" : "[geo_distance] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
      "line" : 18,
      "col" : 8
    }
  },
  "status" : 400
}

Help me please to figure out what I am doing wrong


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
770 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your filter part was mal formated, try :

{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": [
        {
          "geo_distance": {
            "distance": "1000km",
            "geoLocation": {
              "lat": 31.966467334184614,
              "lon": 35.83242623178664
            }
          }
        },
        {
          "range": {
            "map_date": {
              "gte": "now-3w/w",
              "lte": "now/w"
            }
          }
        }
      ]
    }
  }
}

Il your filter array you list a list of {}, take a look at: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...