2017-02-21 7 views
0

Ich habe die Mapping-Abfrage verwendet, um eine Suche in ElasticSearch durchzuführen, und es funktioniert wie folgt.Python ElasticSearch Query-Fehler

{ 
       "query": { 
        "bool" : { 
         "must" : { 
          "match_all" : {} 
         }, 
         "filter" : { 
          "geo_distance" : { 
           "distance" : "{}mi".format(list_info.radius_b), 
           'location': { 
            "lat": zip.lat, 
            "lon": zip.lng 
           } 
          } 
         }, 
        }, 
       }, 
       "sort" : [ 
        { 
         "_geo_distance" : { 
          'location': {"lat": zip.lat, 
             "lon": zip.lng}, 
          "order" : "asc", 
          "unit" : "mi", 
          "mode" : "min", 
          "distance_type" : "sloppy_arc" 
         } 
        } 
       ], 
       "from": 0, 
       "size": 0, 
      } 

Aber auch füge ich "Begriffe", die ich erhalte Fehler: TransportError (400, u'parsing_exception‘, u '[Begriff] fehlerhafte Abfrage, erwartet [END_OBJECT] aber gefunden [FIELD_NAME]

)
{ 
       "query": { 
        "bool" : { 
         "must" : { 
          "match_all" : {} 
         }, 
         "filter" : { 
          "geo_distance" : { 
           "distance" : "{}mi".format(list_info.radius_b), 
           'location': { 
            "lat": zip.lat, 
            "lon": zip.lng 
           } 
          } 
         }, 
        }, 
        "term" : { "status" : "approved" } 
       }, 
       "sort" : [ 
        { 
         "_geo_distance" : { 
          'location': {"lat": zip.lat, 
             "lon": zip.lng}, 
          "order" : "asc", 
          "unit" : "mi", 
          "mode" : "min", 
          "distance_type" : "sloppy_arc" 
         } 
        } 
       ], 
       "from": 0, 
       "size": 0, 
      } 

Antwort

3

Ihre neue term Abfrage muss innerhalb der bool/filter Abfrage befinden:

{ 
    "query": { 
    "bool": { 
     "must": { 
     "match_all": {} 
     }, 
     "filter": [ 
     { 
      "geo_distance": { 
      "distance": "{}mi".format(list_info.radius_b), 
      "location": { 
       "lat": zip.lat, 
       "lon": zip.lng 
      } 
      } 
     }, 
     { 
      "term": { 
      "status": "approved" 
      } 
     } 
     ] 
    } 
    }, 
    "sort": [ 
    { 
     "_geo_distance": { 
     "location": { 
      "lat": zip.lat, 
      "lon": zip.lng 
     }, 
     "order": "asc", 
     "unit": "mi", 
     "mode": "min", 
     "distance_type": "sloppy_arc" 
     } 
    } 
    ], 
    "from": 0, 
    "size": 0 
} 
+0

Konnten Sie diese Arbeit machen? – Val