0

Ok maybe I am missing some core concept of Elasticsearch but I am new to this and trying to achieve something that looked sensible to me.

Lets imagine we have a number of runners in a race, with checkpoints around the track.

Out base documents may look like:

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

My question is, does it make sense to be able to extend the list of checkpoints and if so, what would be an example (POST) request to do that?

Update:

Expected result:

{
    "name"       : "John Smith",
    "age"        : "31",
    "checkpoints": [
        {
            "checkpoint" : "Race Start"
            "timestamp"  : "..."
        },
        {
            "checkpoint" : "Checkpoint1"
            "timestamp"  : "..."
        },
        {
            "checkpoint" : "Checkpoint2"
            "timestamp"  : "..."
        }
    ]
 }
2
  • What you mean by to extend the list of checkpoints? Add another object to array? Commented Jul 14, 2016 at 9:29
  • Added expected result Commented Jul 14, 2016 at 9:31

1 Answer 1

1

You don't have to do something specific.

When you run PUT query:

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

You will obtain exactly the same in GET query:

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

Result:

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

So, when you run:

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"  : "..."
        }
    ]
}'

You will obtain:

{"_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"  : "..."
            }
        ]
    }}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, Sir! I've spend about 2 hours and tried all kinds of special schemas, using /_update scripts, etc. It's always simpler than you think.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.