亲,只收二进制

GEO query 查询报错

Elasticsearch | 作者 xuewb_1024 | 发布于2018年04月23日 | 阅读数:6145

最近学习Elasticsearch,但是涉及geo地理信息查询,总是报错,希望大家给点意见!!!
 
1.  我设置了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"
        }
      }
    }
  }
}
 
2. 添加了几条数据;
 
3.代码查询报错,代码如下


public String geoFoundDoc(String index,String type,double lat,double lon,double distance)

 QueryBuilder qb = geoDistanceQuery("location") .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;
 }
 
4. 控制台错误信息

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]
 

 
问题:  代码在黑色那一行一直报错,希望大家给些帮助!!跪等!!我要做的查询功能是:中心点一定距离内的文档,返回文档数据;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
已邀请:

JackGe

赞同来自: xuewb_1024 CarrieJin

先使用curl方式测试下查询语句能否正确查询
GET /student/stu_type/_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "200km",
                    "location" : {
                        "lat" : x,
                        "lon" : y
                    }
                }
            }
        }
    }
}再根据错误信息java.lang.IllegalStateException: unexpected byte [0xff],这个是在netty通信层出错,请检查下es集群版本和是程序中es client的版本是否一致。
 

要回复问题请先登录注册