gpt4 book ai didi

java - Elasticsearch 扩展内部文档数组

转载 作者:行者123 更新时间:2023-12-01 09:42:07 24 4
gpt4 key购买 nike

好吧,也许我错过了 Elasticsearch 的一些核心概念,但我对此很陌生,并试图实现一些对我来说看起来合理的东西。

让我们想象一下,我们有很多运行者参加一场比赛,赛道周围有检查站。

基础文档可能如下所示:

{
"name" : "John Smith",
"age" : "31",
"checkpoints": [
{
"checkpoint" : "Race Start"
"timestamp" : "..."
}
]
}

我的问题是,能够扩展检查点列表是否有意义?如果是,那么执行此操作的示例(POST)请求是什么?

更新:

预期结果:

{
"name" : "John Smith",
"age" : "31",
"checkpoints": [
{
"checkpoint" : "Race Start"
"timestamp" : "..."
},
{
"checkpoint" : "Checkpoint1"
"timestamp" : "..."
},
{
"checkpoint" : "Checkpoint2"
"timestamp" : "..."
}
]
}

最佳答案

您不必执行特定的操作。

当您运行 PUT 查询时:

curl -XPUT localhost:9200/your_index/your_type/1 -d '{
"name" : "John Smith",
"age" : "31",
"checkpoints": [
{
"checkpoint" : "Race Start",
"timestamp" : "..."
}
]
}'

您将在 GET 查询中获得完全相同的结果:

curl -XGET localhost:9200/your_index/your_type/1

结果:

{"_index":"your_index","_type":"your_type","_id":"1","_version":2,"found":true,"_source":{
"name" : "John Smith",
"age" : "31",
"checkpoints": [
{
"checkpoint" : "Race Start",
"timestamp" : "..."
}
]
}}

所以,当你运行时:

curl -XPUT localhost:9200/your_index/your_type/1 -d '{
"name" : "John Smith",
"age" : "31",
"checkpoints": [
{
"checkpoint" : "Race Start",
"timestamp" : "..."
},
{
"checkpoint" : "Checkpoint1",
"timestamp" : "..."
},
{
"checkpoint" : "Checkpoint2",
"timestamp" : "..."
}
]
}'

您将获得:

{"_index":"your_index","_type":"your_type","_id":"1","_version":3,"found":true,"_source":{
"name" : "John Smith",
"age" : "31",
"checkpoints": [
{
"checkpoint" : "Race Start",
"timestamp" : "..."
},
{
"checkpoint" : "Checkpoint1",
"timestamp" : "..."
},
{
"checkpoint" : "Checkpoint2",
"timestamp" : "..."
}
]
}}

关于java - Elasticsearch 扩展内部文档数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38370427/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com