Debug获取ElasticSearch响应,而正常运行则不会

时间:2015-05-04 21:57:56

标签: java spring debugging elasticsearch

您好我是ElasticSearch的新手,但我遇到了这个有趣的错误。如果我在调试模式下运行我的项目,我的SearchResponse会返回我的查询。但是,如果我正常运行它,它不会。这有什么原因吗?

我正在使用ElasticSearch 1.4.2,并使用Java API,传输客户端。

我的调试消息在调试模式下显示:

DEBUG | Client Established
DEBUG | db created
DEBUG | Trying to get a response...
DEBUG | Response 1: org.elasticsearch.action.index.IndexResponse@1aa93fb
DEBUG | Search Response: {
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "db",
      "_type" : "user",
      "_id" : "1",
      "_score" : 1.0,
      "_source":{"user":"matt","content":"trying out Elasticsearch"}
    }, {
      "_index" : "db",
      "_type" : "user",
      "_id" : "2",
      "_score" : 1.0,
      "_source":{"user":"jim","content":"trying out Elasticsearch"}
    } ]
  }
}

我的调试信息在正常运行时显示:

DEBUG | Client Established
DEBUG | db created
DEBUG | Trying to get a response...
DEBUG | Response 1: org.elasticsearch.action.index.IndexResponse@d05471
DEBUG | Search Response: {  "took" : 1, 
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}
DEBUG | elasticsearch response: 0 hits

正常运行它没有给予elasticsearch足够的时间来搜索它需要的东西吗?

查询是:

    SearchResponse allHits1 = client.prepareSearch("costamesadb").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();

1 个答案:

答案 0 :(得分:0)

可能是您的应用程序正在创建数据,然后很快就会搜索创建的数据。搜索不会立即显示新创建的数据。

请参阅status.ng.bluemix.net

您可以使用实时的GET API,请参阅Near Real time search