如何在Elasticsearch结果的顶层添加参数?

huangapple go评论81阅读模式
英文:

How to add parameter at the top level of the elasticsearch results?

问题

这是在Elasticsearch中尝试的实验,我想在结果的顶层添加参数是否可能。以下是典型的Elasticsearch结果:

  1. {
  2. "_index": "testing",
  3. "_type": "reading",
  4. "_id": "bwDimoUBulk-8kIUdLcv",
  5. "_version": 2,
  6. "_seq_no": 7468,
  7. "_primary_term": 15,
  8. "found": true,
  9. "_source": {
  10. "device": {
  11. "id": 1435
  12. },
  13. "service": 3,
  14. "value": 0,
  15. "timestamp": 1723672453,
  16. "created": "2024-08-15T07:54:13+10:00",
  17. "updated": "2023-01-10T18:57:28+10:00"
  18. }
  19. }

我想在这个示例中添加timestamp

  1. {
  2. "_index": "testing",
  3. "_type": "reading",
  4. "_id": "bwDimoUBulk-8kIUdLcv",
  5. "_version": 2,
  6. "_seq_no": 7468,
  7. "_primary_term": 15,
  8. "found": true,
  9. "_source": {
  10. "device": {
  11. "id": 1435
  12. },
  13. "service": 3,
  14. "value": 0,
  15. "timestamp": 1723672453,
  16. "created": "2024-08-15T07:54:13+10:00",
  17. "updated": "2023-01-10T18:57:28+10:00"
  18. },
  19. "timestamp": 1723672453 //<-- 这是我想要在结果中添加的部分
  20. }

我在结果的顶层添加了timestamp

英文:

I'm trying to experiment if this is possible in Elasticsearch wherein I can add parameter at the top level of the result.

This is a typical result from elasticsearch

  1. {
  2. &quot;_index&quot;: &quot;testing&quot;,
  3. &quot;_type&quot;: &quot;reading&quot;,
  4. &quot;_id&quot;: &quot;bwDimoUBulk-8kIUdLcv&quot;,
  5. &quot;_version&quot;: 2,
  6. &quot;_seq_no&quot;: 7468,
  7. &quot;_primary_term&quot;: 15,
  8. &quot;found&quot;: true,
  9. &quot;_source&quot;: {
  10. &quot;device&quot;: {
  11. &quot;id&quot;: 1435
  12. },
  13. &quot;service&quot;: 3,
  14. &quot;value&quot;: 0,
  15. &quot;timestamp&quot;: 1723672453,
  16. &quot;created&quot;: &quot;2024-08-15T07:54:13+10:00&quot;,
  17. &quot;updated&quot;: &quot;2023-01-10T18:57:28+10:00&quot;
  18. }
  19. }

I want to add the timestamp in this example

  1. {
  2. &quot;_index&quot;: &quot;testing&quot;,
  3. &quot;_type&quot;: &quot;reading&quot;,
  4. &quot;_id&quot;: &quot;bwDimoUBulk-8kIUdLcv&quot;,
  5. &quot;_version&quot;: 2,
  6. &quot;_seq_no&quot;: 7468,
  7. &quot;_primary_term&quot;: 15,
  8. &quot;found&quot;: true,
  9. &quot;_source&quot;: {
  10. &quot;device&quot;: {
  11. &quot;id&quot;: 1435
  12. },
  13. &quot;service&quot;: 3,
  14. &quot;value&quot;: 0,
  15. &quot;timestamp&quot;: 1723672453,
  16. &quot;created&quot;: &quot;2024-08-15T07:54:13+10:00&quot;,
  17. &quot;updated&quot;: &quot;2023-01-10T18:57:28+10:00&quot;
  18. },
  19. &quot;timestamp&quot;: 1723672453, &lt;-- this is what I want to add in the result
  20. }

I add the timestamp at the top level of the result.

答案1

得分: 1

目前,您无法更改Elasticsearch响应的顶层结构。恐怕您需要在客户端级别进行更改。您唯一能够控制响应字段的方式是选择是否要包含它们或不包含它们,详情请参考:https://www.elastic.co/guide/en/elasticsearch/reference/master/common-options.html#common-options-response-filtering

英文:

at the moment, you cannot change the top-level structure of the Elasticsearch response. I'm afraid you need to do that at the client level. The only control you have over the response fields is whether you want to include them or not https://www.elastic.co/guide/en/elasticsearch/reference/master/common-options.html#common-options-response-filtering

huangapple
  • 本文由 发表于 2023年2月24日 09:04:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75551765.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定