大家好,我是ElasticSearch的新手,但我遇到了一个有趣的bug。如果我在调试模式下运行我的项目,我的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();发布于 2015-05-06 17:56:08
这可能是因为您的应用程序正在创建数据,然后很快就会搜索所创建的数据。新创建的数据不会立即显示在搜索中。
请参阅Near Real time search
您可以使用实时的GET API,请参阅GET API
https://stackoverflow.com/questions/30040694
复制相似问题