ElasticSearch查询特定字段返回数组

时间:2018-03-01 11:48:15

标签: elasticsearch

我使用ElasticSearch 2.4存储文档。为了查询它们,我调用这个命令:

{
   "query":{
      "query_string":{
         "default_field":"Text",
         "query": "This is my full search query"
      },
   }
}

结果如下:

{
   "took":2,
   "timed_out":false,
   "_shards":{
      "total":5,
      "successful":5,
      "failed":0
   },
   "hits":{
      "total":862,
      "max_score":4.1904,
      "hits":[
         {
            "_index":"education",
            "_type":"e353edaa-9b83-419b-952b-888b5db21928",
            "_id":"9b015845-07b1-499d-96fa-c0ede2d60f46",
            "_score":4.1904,
            "_source":{
               "Shared":true,
               "Text":"Hello world hello world hello world",
               "ID":"9b015845-07b1-499d-96fa-c0ede2d60f46",
               "UserId":"e2223edaa-9b83-419b-952b-888b5db21928",
               "PublishDate":"2017-04-13T11:55:25.2394266Z"
            }
         }
      ]
   }
}

现在,而不是转移所有"记录"通过网络,我想发送相同的查询,但现在,返回的信息将只包含几个字段(IDPublishedDate)。所以我调用了这个查询:

{
   "fields" : ["ID", "PublishDate"],
   "query":{

      "query_string":{
         "default_field":"Text",
         "query": "Hello"
      },
   }
}

结果如下:

{
   "took":43,
   "timed_out":false,
   "_shards":{
      "total":5,
      "successful":5,
      "failed":0
   },
   "hits":{
      "total":1,
      "max_score":0.09824822,
      "hits":[
         {
            "_index":"education",
            "_type":"410c24b1-78a8-4ee4-984d-9cfa2331120f",
            "_id":"63ea1591-7126-4512-9c8b-2e3fcdcc5081",
            "_score":0.09824822,
            "fields":{
               "PublishDate":[
                  "2018-02-28T23:28:08.8376343Z"
               ],
               "ID":[
                  "63ea1591-7126-4512-9c8b-2e3fcdcc5081"
               ]
            }
         }
      ]
   }
}

如您所见,这两个字段(PublishedDateID)将作为字符串数组返回。我不明白为什么?

第一个查询(这里提到)刚刚证明了这个"记录"只有一个ID(" 9b015845-07b1-499d-96fa-c0ede2d60f46")只有一个PublishedDate(" 2017-04-13T11:55:25.2394266Z&# 34)。那么为什么在询问结果中的特定字段时它是否作为数组返回?

有人有解释吗?

0 个答案:

没有答案