Elasticsearch 扩展内部文档数组
Elasticsearch extend inner document array
好吧,也许我遗漏了 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" : "..."
}
]
}}
好吧,也许我遗漏了 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" : "..."
}
]
}}