2015-02-09 40 views
0

我想對elasticsearch進行geo_point查詢,但它對我來說不能正常工作。我總是得到空的結果geo_polygon查詢。也許我的映射是錯誤的或我得到數據的方式。elasticsearch geo_point不能正常工作

  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 ; 
    

我在SQL創建一個JSON對象,因爲發送lat_lon作爲一個字符串沒有工作對我來說(彈性不要將字符串拆分爲寫她的http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-geo-point-type.html#_lat_lon_as_string_6

  • 創建從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" 
        } 
    }' 
    
  • 爲例在elastichsearch

    { 
        _index: botanique_localisation 
        _type: specimens 
        _id: 38C8F872A449491C881791DE8B501B17 
        _score: 1.4142135 
        _source: { 
         LOCATION: { 
          lon: 47.05 
          lat: -19.95 
         } 
        } 
    } 
    
  • 工作範圍查詢

     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 } 
        } 
    },... 
    
  • 現在的樂趣不工作的一部分!與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 }        
             ] 
            } 
           } 
          } 
         } 
        } 
    }' 
    
  • 這回沒有命中!

    我失蹤了什麼? 謝謝

    回答

    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 
              } 
             } 
            } 
           } 
          } 
         } 
        }'