Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Java API向Elasticsearch结果添加_时间戳_Java_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Java,elasticsearch" /> elasticsearch,Java,elasticsearch" />

使用Java API向Elasticsearch结果添加_时间戳

使用Java API向Elasticsearch结果添加_时间戳,java,elasticsearch,Java,elasticsearch,我有一个Elasticsearch索引,它在每条记录上填充了\u时间戳。使用Marvel或curl,我可以在结果的“字段”部分获得时间戳,例如: GET index/type/_search?fields=_timestamp,_source { "took": 11, "timed_out": false, "_shards": { "total": 3, "successful": 3, "failed": 0 }, "hit

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

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进行搜索时,我无法让它返回
\u时间戳

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

有人能告诉我如何要求时间戳吗?

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

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

.setFields(“_timestamp”).setFields在我的ES版本中不是可用的方法,但是我使用了addFields,它仍然没有返回时间戳。还有其他想法吗<代码>SearchRequestBuilder builder=client.prepareSearch(index).addFacet(facet).addFields(“\u timestamp”,“\u source”).setFrom(start).setSize(limit);返回生成器那是什么版本?Elasticsearch 1.1.1版。当我添加.addFields(“U timestamp”)时,源代码就消失了。但是当我使用.addFields(“timestamp”,“_source”)时,源代码再次返回,但仍然没有时间戳,即使它正在存储。1.1.1,哎哟:)这很奇怪,因为我可以在1.1.1版本中找到。不幸的是,1.1.1:(是的,但这是针对GetRequestBuilder的,而我使用