求帮忙!!Elasticsearch 地理信息GEO查询

helloworld_xwb 2018-04-23 05:18:21
最近项目需要学习es的geo查询,遇到查询问题卡了我一天,跪求大神解答!
我在Elasticsearch添加一个Index,并添加了mapping, 如下:
{
"student": {
"aliases": {},
"mappings": {
"stu_type": {
"properties": {
"@timestamp": {
"type": "long"
},
"age": {
"type": "integer"
},
"location": {
"type": "geo_point"
},
"name": {
"type": "keyword",
"store": true
},
"school": {
"type": "text"
}
}
}
},
"settings": {
"index": {
"refresh_interval": "10s",
"number_of_shards": "5",
"provided_name": "student",
"creation_date": "1524293244867",
"number_of_replicas": "0",
"uuid": "liceQ_-LQEOaLrYsS2gpHw",
"version": {
"created": "6020399"
}
}
}
}
}
之后又添加了几条数据,开始查询。

查询代码:
/**
* 获取中心点周围指定范围内的文档
* @param index 索引名称
* @param location 地理位置属性名
* @param lat 纬度
* @param lon 经度
* @param distance 距离/Km
* @return
*/
public String geoFoundDoc(String index,String type,double lat,double lon,double distance){
QueryBuilder qb = geoDistanceQuery("location") //field
.point(lat, lon)
.distance(distance, DistanceUnit.KILOMETERS);
SearchResponse searchResponse = client.prepareSearch(index).setTypes(type).setQuery(qb).execute().actionGet();
SearchHit[] hits = searchResponse.getHits().getHits();
String docStr = "";
for (SearchHit doc:hits){
docStr += doc.getSourceAsString();
}
return docStr;
}

标记那一行一直报错,控制台打印错误信息如下:

java.lang.IllegalStateException: unexpected byte [0xff]
at org.elasticsearch.common.io.stream.StreamInput.readBoolean(StreamInput.java:412) ~[elasticsearch-5.6.3.jar:5.6.3]
at org.elasticsearch.common.io.stream.StreamInput.readBoolean(StreamInput.java:402) ~[elasticsearch-5.6.3.jar:5.6.3]
at org.elasticsearch.search.builder.SearchSourceBuilder.<init>(SearchSourceBuilder.java:211) ~[elasticsearch-5.6.3.jar:5.6.3]
at org.elasticsearch.common.io.stream.StreamInput.readOptionalWriteable(StreamInput.java:733) ~[elasticsearch-5.6.3.jar:5.6.3]
at org.elasticsearch.action.search.SearchRequest.readFrom(SearchRequest.java:421) ~[elasticsearch-5.6.3.jar:5.6.3]
at org.elasticsearch.common.io.stream.Streamable.lambda$newWriteableReader$0(Streamable.java:51) ~[elasticsearch-5.6.3.jar:5.6.3]
at org.elasticsearch.transport.RequestHandlerRegistry.newRequest(RequestHandlerRegistry.java:56) ~[elasticsearch-5.6.3.jar:5.6.3]
at org.elasticsearch.transport.TcpTransport.handleRequest(TcpTransport.java:1508) ~[elasticsearch-5.6.3.jar:5.6.3]
at org.elasticsearch.transport.TcpTransport.messageReceived(TcpTransport.java:1382) ~[elasticsearch-5.6.3.jar:5.6.3]
at org.elasticsearch.transport.netty4.Netty4MessageChannelHandler.channelRead(Netty4MessageChannelHandler.java:64) ~[transport-netty4-client-5.6.3.jar:5.6.3]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310) ~[netty-codec-4.1.13.Final.jar:4.1.13.Final]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:297) ~[netty-codec-4.1.13.Final.jar:4.1.13.Final]
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:413) ~[netty-codec-4.1.13.Final.jar:4.1.13.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265) ~[netty-codec-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.handler.logging.LoggingHandler.channelRead(LoggingHandler.java:241) ~[netty-handler-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:545) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) ~[netty-transport-4.1.13.Final.jar:4.1.13.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) ~[netty-common-4.1.13.Final.jar:4.1.13.Final]
at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_152]

死活找不出问题在哪里,跪求大神解决!!!
...全文
812 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,713

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧