elasticsearch geo_point无法正常工作

时间:2015-02-09 13:06:48

标签: elasticsearch

我想对elasticsearch进行geo_point查询,但它对我来说不起作用。我总是得到geo_polygon查询的空结果。也许我的映射是错误的或我获取数据的方式。

  1. 映射:

     curl -XPUT 'localhost:9200/botanique_localisation/' -d '{
        "mappings":{
            "botanique_localisation" : {
                "_all" : {"enabled" : true},
                "_index" : {"enabled" : true},
                "_id" : {"index": "not_analyzed", "store" : false},
                "properties" : {
                    "_id" : {"type" : "string", "store" : "no","index": "not_analyzed"  } ,
                    "LOCATION" : { "type" : "geo_point","lat_lon" :true ,"validate":true  , "store":"yes" }             
                }
            }
        }
      }'
    
  2. 在oracle中创建视图

     create view all_specimens_localisation as select RAWTOHEX( SPECIMENS.occurrenceid ) as "_id" , 
     decode(LOCALISATIONS.decimalLatitude ||',' || LOCALISATIONS.decimalLongitude, ',', null ,
      '{"lat":' || replace(LOCALISATIONS.decimalLatitude,',' ,'.' ) ||',"lon":' || replace(LOCALISATIONS.decimalLongitude , ',' ,'.' ) || '}'
     ) as location 
     from SPECIMENS left outer join ... where rownum < 1000 ;
    
  3. 我在sql中创建了一个json对象,因为将lat_lon作为字符串发送并不适合我(弹性不要将字符串拆分为写http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-geo-point-type.html#_lat_lon_as_string_6

    1. 创建从oracle到elasticsearch的河流

         curl -XPUT 'localhost:9200/_river/localisation_river/_meta' -d '{
            "type" : "jdbc",
            "jdbc" : {
              "index" : "botanique_localisation",
              "bulk_size" : 2000,
              "max_bulk_requests" : 10,
              "bulk_flush_interval" : "1s",
              "type" : "specimens",
              "url" : "********",
              "user" : "********",
              "password" : "********", 
              "sql" : "select * from all_specimens_localisation"
           }
      }'
      
    2. 弹性研究中索引数据的例子

      {
          _index: botanique_localisation
          _type: specimens
          _id: 38C8F872A449491C881791DE8B501B17
          _score: 1.4142135
          _source: {
              LOCATION: {
                  lon: 47.05
                  lat: -19.95
              }
          }
      }
      
    3. 工作范围查询

             curl -XGET 'localhost:9200/botanique_localisation/specimens/_search?size=10&pretty' -d '
      { "query": {  "bool": { "must": [
          { "range": {
                  "LOCATION.lon": {
                      "from": 47.04,
                      "to": 47.08
                  }
              }
          },{ "range": {
                  "LOCATION.lat": {
                      "from": -20,
                      "to": -19.90
                  }
              }
          }
      ]}}}'
      

      结果:

      hits:{[
      {    "_index": botanique_localisation,
          "_type": specimens,
          "_id": 38C8F872A449491C881791DE8B501B17,
          "_score": 1.4142135,
          "_source": {
              "LOCATION": { "lon": 47.05, "lat": -19.95 }
          }
      },...
      
    4. 现在好玩的不工作了!使用geo_polygon查询:

      curl -XGET 'localhost:9200/botanique_localisation/_search?size=10&pretty' -d '{
          "query":{
              "filtered" : {
                  "query" : { "match_all" : {}},
                  "filter" : {
                      "geo_polygon" : {
                          "LOCATION" : {
                              "points" : [
                                  { "lat": 100, "lon": -100},
                                  { "lat": 100, "lon": 100},
                                  { "lat": -100, "lon": 100 },
                                  { "lat": -100 , "lon": -100 }                            
                              ]
                          }
                      }
                  }
              }
          }
      }'
      
    5. 此返回没有命中!

      我失踪了什么? 谢谢

1 个答案:

答案 0 :(得分:0)

此查询工作:

    curl -XGET 'localhost:9200/botanique_localisation/_search?pretty' -d '{
        "query" : {
            "filtered" : {
                "filter" : {
                    "geo_bounding_box" : {
                        "type" : "indexed",
                        "LOCATION" : {
                            "top_left" : {
                                "lat" : 50,
                                "lon" : -50
                            },
                            "bottom_right" : {
                                "lat" :-50,
                                "lon" : 50
                            }
                        }
                    }
                }
            }
        } 
    }'