英文:
How to add parameter at the top level of the elasticsearch results?
问题
这是在Elasticsearch中尝试的实验,我想在结果的顶层添加参数是否可能。以下是典型的Elasticsearch结果:
{
"_index": "testing",
"_type": "reading",
"_id": "bwDimoUBulk-8kIUdLcv",
"_version": 2,
"_seq_no": 7468,
"_primary_term": 15,
"found": true,
"_source": {
"device": {
"id": 1435
},
"service": 3,
"value": 0,
"timestamp": 1723672453,
"created": "2024-08-15T07:54:13+10:00",
"updated": "2023-01-10T18:57:28+10:00"
}
}
我想在这个示例中添加timestamp
:
{
"_index": "testing",
"_type": "reading",
"_id": "bwDimoUBulk-8kIUdLcv",
"_version": 2,
"_seq_no": 7468,
"_primary_term": 15,
"found": true,
"_source": {
"device": {
"id": 1435
},
"service": 3,
"value": 0,
"timestamp": 1723672453,
"created": "2024-08-15T07:54:13+10:00",
"updated": "2023-01-10T18:57:28+10:00"
},
"timestamp": 1723672453 //<-- 这是我想要在结果中添加的部分
}
我在结果的顶层添加了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
{
"_index": "testing",
"_type": "reading",
"_id": "bwDimoUBulk-8kIUdLcv",
"_version": 2,
"_seq_no": 7468,
"_primary_term": 15,
"found": true,
"_source": {
"device": {
"id": 1435
},
"service": 3,
"value": 0,
"timestamp": 1723672453,
"created": "2024-08-15T07:54:13+10:00",
"updated": "2023-01-10T18:57:28+10:00"
}
}
I want to add the timestamp
in this example
{
"_index": "testing",
"_type": "reading",
"_id": "bwDimoUBulk-8kIUdLcv",
"_version": 2,
"_seq_no": 7468,
"_primary_term": 15,
"found": true,
"_source": {
"device": {
"id": 1435
},
"service": 3,
"value": 0,
"timestamp": 1723672453,
"created": "2024-08-15T07:54:13+10:00",
"updated": "2023-01-10T18:57:28+10:00"
},
"timestamp": 1723672453, <-- this is what I want to add in the result
}
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论