6

How to insert the following JSON nested array abject into Elasticsearch index named "index_19_7_16"?

{
      "hour": [
        {
          "time": "00:00",
          "master_id": [
            {
              "m.id": 111,
              "m.value": 222
            },
            {
              "m.id": 113,
              "m.value": 444
            }
          ],
          "child_id": [
            {
              "c.id": 77,
              "c.value": 222
            },
            {
              "c.id": 7751,
              "c.value": 444
            }
          ]
        },
        {
          "time": "01:00",
          "master_id": [
            {
              "m.id": 111,
              "m.value": 222
            },
            {
              "m.id": 113,
              "m.value": 444
            }
          ],
          "child_id": [
            {
              "c.id": 77,
              "c.value": 222
            },
            {
              "c.id": 7751,
              "c.value": 444
            }
          ]
        }
      ]
    }

Do I need to created mapping before or just insert the JSON dynamically into elastic index.

1 Answer 1

5

You need to create the mapping upfront and specifically mention that some fields have to be "type":"nested" otherwise ES will just create objects. Here I specifically refer to nested type of fields in ES.

If by nested you meant just the nested nature of the document, then you don't have to do anything.

Sign up to request clarification or add additional context in comments.

4 Comments

Andrei Stefan: Thanks, and what way is better for searching/aggregations issues , either create "type":"nested" or just insert the Json without any mapping?
The nested story is about associating a field value with another field value from the same nested field. In your case, if your future queries care about "m.id": 111 to be considered as "connected" with "m.value": 222 then you need nested.
My future aggregation would be sum all "m.id": 111, values between ranges of hours.. For instance: SUM+= between 00:00-02:00 all values from "m.id": 111
Please, read the docs link I provided in the answer. The example there is relevant: first name and last name. Obviously, each person has one of those. With nested fields a certain first name belongs to a certain last name. With non-nested fields that association is lost. This is all about with nested fields.

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.