美文网首页
elasticsearch No value specifie

elasticsearch No value specifie

作者: 吴世浩 | 来源:发表于2018-09-20 23:38 被阅读335次

一、好言

智商总要通过各种考试去证明和反省,试题不会出问题,公式不会出问题,要么是自己粗心,要么是自己蠢,接受智商高低这件事情,人人都驾轻就熟。


二、问题

 @Test
    public void test() throws Exception{
        List inList = new ArrayList();
        try {
            NativeSearchQueryBuilder searchQuery = new NativeSearchQueryBuilder();
            searchQuery.withIndices("test_index");
            searchQuery.withTypes("t_test");
            searchQuery.withPageable(new PageRequest(0, 0));
            BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
            queryBuilder.filter(QueryBuilders.termsQuery("mobileNo",  inList.toArray(new String[]{"123","456","123"});));
            searchQuery.withQuery(queryBuilder);
            System.out.println(searchQuery.build().getQuery().toString());
            List<Test> resultList  = elasticsearchTemplate.queryForList(searchQuery.build(), Test.class);
            /*
            searchQuery.withFilter(QueryBuilders.termsQuery("mobile", inList.toArray()));
            System.out.println(searchQuery.build().getFilter().toString());
            List<Test> resultList  = elasticsearchTemplate.queryForList(searchQuery.build(), Test.class);*/
        }catch (Exception e){
            e.printStackTrace();
        }
    }
Failed to execute phase [dfs], all shards failed; shardFailures {[felf1bKUSY6sbP3-1ZJCoQ][test_index][0]: RemoteTransportException[[node-3][172.20.21.37:9300][indices:data/read/search[phase/dfs]]]; nested: SearchParseException[failed to parse search source [{"from":0,"size":1000,"query":{"bool":{"filter":{"terms":{"mobileNo":["3124124312431","423142143214"]}}}}}]]; nested: QueryParsingException[No value specified for terms query]; }
    at org.elasticsearch.action.search.AbstractSearchAsyncAction.onFirstPhaseResult(AbstractSearchAsyncAction.java:206)
    at org.elasticsearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:152)
    at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:46)
    at org.elasticsearch.transport.netty.MessageChannelHandler.handleException(MessageChannelHandler.java:184)
    at org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:174)
    at org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:122)
    at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
    at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
    at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)
    at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443)
    at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)
    at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
    at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
    at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
    at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
    at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: [test_index] QueryParsingException[No value specified for terms query]
    at org.elasticsearch.index.query.TermsQueryParser.parse(TermsQueryParser.java:105)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:250)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:263)
    at org.elasticsearch.index.query.BoolQueryParser.parse(BoolQueryParser.java:91)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:250)
    at org.elasticsearch.index.query.IndexQueryParserService.innerParse(IndexQueryParserService.java:324)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:224)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:219)
    at org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33)
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:856)
    at org.elasticsearch.search.SearchService.createContext(SearchService.java:667)
    at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:633)
    at org.elasticsearch.search.SearchService.executeDfsPhase(SearchService.java:264)
    at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:360)
    at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:357)
    at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33)
    at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:77)
    at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:378)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
    ... 3 more

在查询的时候,termsQuery中mobileNo的值传入参数有null值,因此会报错,这个错误折腾了我好久,我之前测试查询5条,10条都没问题,但是查询超过10条就一直报错,最初以为是某个属性设置问题,还专门修改了max_result_window的值。

withFilter
{
  "terms" : {
    "mobile" : [ "123456", "7645747645, "567474576547", "7654747654", "7654747654", "754567547564" ]
  }
}



withQuery:
{
  "bool" : {
    "filter" : {
      "terms" : {
        "mobile" : [ "123456", "7645747645, "567474576547", "7654747654", "7654747654", "754567547564" ]
      }
    }
  }
}

这两种那种效率更高?

三、总结

所以es对于null不友好,后续慢慢通过遇到问题来更加加深理解。

相关文章

网友评论

      本文标题:elasticsearch No value specifie

      本文链接:https://www.haomeiwen.com/subject/kmynnftx.html