No records return when using transport client, 100 records return when using restful api?


(Cherry Zhang) #1

while I debug my code, the transport client always return 0 records, but when I copy the request builder's query string to my restful client, and run the query, 100 records return, can't figure out why?

here is all my Search request builder values I get from my IDE debugger:

SearchRequest{searchType=QUERY_THEN_FETCH, indices=[trip-2016-12, trip-2016-11], indicesOptions=IndicesOptions[id=38, ignore_unavailable=false, allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, allow_alisases_to_multiple_indices=true, forbid_closed_indices=true], types=[], routing='null', preference='null', requestCache=null, scroll=null, source={
  "query" : {
    "bool" : {
      "filter" : [
        {
          "range" : {
            "startTime" : {
              "from" : "2016-11-30T00:00:00.000Z",
              "to" : "2016-12-30T00:00:00.000Z",
              "include_lower" : true,
              "include_upper" : true,
              "boost" : 1.0
            }
          }
        }
      ],
      "disable_coord" : false,
      "adjust_pure_negative" : true,
      "boost" : 1.0
    }
  },
  "ext" : { }
}}

the query I past in my restful client:

http://localhost:9200/trip-2016-11,trip-2016-12/_search?scroll=1m
   {
  "query" : {
    "bool" : {
      "filter" : [
        {
          "range" : {
            "startTime" : {
              "from" : "2016-11-30T00:00:00.000Z",
              "to" : "2016-12-30T00:00:00.000Z",
              "include_lower" : true,
              "include_upper" : true,
              "boost" : 1.0
            }
          }
        }
      ],
      "disable_coord" : false,
      "adjust_pure_negative" : true,
      "boost" : 1.0
    }
  },
  "ext" : { }
}

(David Pilato) #2

I don't see your code so I can't really tell.
May be you are doing that in a test context and you forgot to refresh the index before searching?


(Cherry Zhang) #3

I have found the root cause by catching a tcpdump, the transport client fail silently for the exception:

org.elasticsearch.transport.RemoteTransportException: [fPZHXSt][127.0.0.1:9300][indices:data/read/search[phase/query]] Caused by: org.elasticsearch.ElasticsearchParseException: failed to parse date field [Wed Nov 30 00:00:00 UTC 2016] with format [yyyy-MM-dd'T'HH:mm:ss.SSS'Z'] at org.elasticsearch.common.joda.DateMathParser.parseDateTime(DateMathParser.java:213) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.common.joda.DateMathParser.parse(DateMathParser.java:66) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.index.mapper.DateFieldMapper$DateFieldType.parseToMilliseconds(DateFieldMapper.java:362) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.index.mapper.DateFieldMapper$DateFieldType.isFieldWithinQuery(DateFieldMapper.java:408) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.index.query.RangeQueryBuilder.getRelation(RangeQueryBuilder.java:408) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.index.query.RangeQueryBuilder.doRewrite(RangeQueryBuilder.java:415) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.index.query.AbstractQueryBuilder.rewrite(AbstractQueryBuilder.java:262) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.index.query.BoolQueryBuilder.rewriteClauses(BoolQueryBuilder.java:506) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.index.query.BoolQueryBuilder.doRewrite(BoolQueryBuilder.java:477) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.index.query.AbstractQueryBuilder.rewrite(AbstractQueryBuilder.java:262) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.search.builder.SearchSourceBuilder.rewrite(SearchSourceBuilder.java:884) ~[elasticsearch-5.0.0.jar:5.0.0]

It is really hard to debug for the client fails silently and tells nothing.


(David Pilato) #4

I'll be super interested in a full JUnit test case if you can write it and share it?
So we can look why it seems to silently fails.
I think you are looking at the Response object in details though.
May be some shards are responding but other shards are not?

Also surprised that REST does not have the same behavior


(Cherry Zhang) #5
{
  "query" : {
    "bool" : {
      "filter" : [
        {
          "range" : {
            "startTime" : {
              "from" : "2016-11-30T00:00:00.000Z",
              "to" : "2016-12-30T00:00:00.000Z",
              "include_lower" : true,
              "include_upper" : true,
              "boost" : 1.0
            }
          }
        }
      ],
      "disable_coord" : false,
      "adjust_pure_negative" : true,
      "boost" : 1.0
    }
  },
  "ext" : { }
}

as you can see, I use the range query, in transport client, originally, I pass date object to range.from() function, and get no exception, but after I check and check a gain, there is error in log. when I changed date object to string object, all things are going fine.


(system) #6

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.