好吧也许我错过了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" : "..."
}
]
}
答案 0 :(得分:1)
您无需做具体的事情。
运行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" : "..."
}
]
}}