2017-02-23 401 views
1

我使用彈簧引導1.5.1與Elasticsearch 2.3.5(對於亨利馬烏推薦系統),所以我有映射一個問題:與@GeoPointField Elasticsearch爲映射

@GeoPointField 
private GeoPoint location; 

從包:

org.springframework.data.elasticsearch.core.geo; 

因此,通過localhost:9200/.../.../_mapping?pretty=1我有:

location: { 
    properties: { 
    lat: { 
    type: "double" 
    }, 
    lon: { 
    type: "double" 
    } 
    } 
} 

但是,我想位置字段的類型爲geo_point

其結果是,當我嘗試:

CriteriaQuery query = new CriteriaQuery(new Criteria("location").within(startLocation, range)); 

我:

QueryParsingException[failed to find geo_point field [location]] 

有誰知道解決辦法嗎? Thx

+0

我有相同的配置和有同樣的問題。我刪除了所有ElasticSearch文件,並在創建實體時收到了正確的映射。 – Aerus

回答

0

問題在於你的映射。它應該是geo_point類型。例如
你可以用curl PUT

curl -XPUT 'http://localhost:9200/your_index/_mapping/your_type' -d ' 
{ 
    "your_type" : { 
     "properties" : { 

      "phone": { 
     "type": "string", "index": "not_analyzed" 
    }, 
    "webSite": { 
     "type": "string", "index": "not_analyzed" 
    } 
    "location": { 
     {"type": "geo_point"}    
    } 
    } 
} 
' 

做時,保存數據,你可以這樣做:

"location":{ 
    "lat":11.68036, 
    "lon":-93.3103 
} 
+0

好的:) @Hosar,我知道這個問題是我的映射,但我怎樣才能解決它與使用Spring Data Elasticsearch? – maystrovyy

+0

你可以用捲曲來做,不知道如何用Spring來做。 – Hosar