java - 使用 Java API 将 _timestamp 添加到 Elasticsearch 结果

标签 java elasticsearch

我有一个 Elasticsearch 索引,它在每条记录上填充了 _timestamp。使用 Marvel 或 curl 我可以在结果的“字段”部分获得 _timestamp 例如:

GET index/type/_search?fields=_timestamp,_source
{
   "took": 11,
   "timed_out": false,
   "_shards": {
      "total": 3,
      "successful": 3,
      "failed": 0
   },
   "hits": {
      "total": 116888,
      "max_score": 1,
      "hits": [
         {
            "_index": "index",
            "_type": "type",
            "_id": "mXJdWqSLSfykbMtChiCRjA",
            "_score": 1,
            "_source": {
               "results": "example",
            },
            "fields": {
               "_timestamp": 1443618319514
            }
         },...

但是,当使用 Java API 进行搜索时,我无法让它返回 _timestamp

SearchRequestBuilder builder= client.prepareSearch(index)
            .addFacet(facet)
            .setFrom(start)
            .setSize(limit);
SearchResponse response = builder.execute().actionGet();

谁能告诉我如何也请求_timestamp

最佳答案

您只需像这样使用 setFields() 方法:

SearchRequestBuilder builder= client.prepareSearch(index)
            .setType(type)
            .addFacet(facet)
            .setFields("_timestamp")          <--- add this line
            .setFrom(start)
            .setSize(limit);
SearchResponse response = builder.execute().actionGet();

关于java - 使用 Java API 将 _timestamp 添加到 Elasticsearch 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33439249/

相关文章:

elasticsearch - elasticsearch _update_by_query不起作用

java - 吞吐量垃圾收集

java - for循环中奇怪的重复次数

algorithm - 确定一个点最接近的预定路线

mysql - 将Mysql查询转换为Elastic Search

elasticsearch - 如果查询中间有数字,则弹性phrase_prefix不起作用

elasticsearch - 使用Elasticsearch进行复合查询

java.lang.ClassCastException :xx cannot be cast to org. apache.avro.generic.IndexedRecord

java - 对数组列表使用 contains() 方法时出现问题

java - 在java中的方法内创建类实例的范围