Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch: How insert nested Json array object into Elasticsearch Index

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.

like image 418
VitalyT Avatar asked Jul 20 '16 12:07

VitalyT


1 Answers

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.

like image 198
Andrei Stefan Avatar answered Oct 08 '22 12:10

Andrei Stefan