0

Very new to elasticsearch

Trying to initialize an index from json using the elasticsearch-py api; using this simple json file to just understand how it's working

{
  "index": "index_name",
  "body": {
    "aliases": {
      "actions": [
        { "add": { "index": "index_name",  "alias": "alias1" } }
      ]
    },
    "mappings": {
      "properties": {
        "age":    { "type": "integer" },
        "email":  { "type": "keyword"  },
        "name":   { "type": "text"  }
      }
    },
    "settings": {
      "number_of_shards":   2,
      "number_of_replicas": 1,
      "index.refresh_interval": "120s"
    }
  }
}

(read a json file, parse out index and body) then the important python part es.indices.create(index=index, body=body)

But I'm getting an error:

elasticsearch.exceptions.TransportError: TransportError(500, 'null_pointer_exception', 'fieldName cannot be null')

I pulled the mapping and alias example from the ES docs. The python works with a different json file that doesn't have aliases in it. When I remove the aliases from this file I get another error about unsupported mapping parameters so I'm not sure where the problem is, but want to solve the alias issue first

Mitch Wilson
  • 109
  • 10

2 Answers2

1

As the accepted answer says, I failed to read the docs. Posting what ended up working for me for a record

a config.json file would look like

"index": "index_1",
"aliases": ["alias1", "alias2"],
"body": {
  "mappings": {...},
  "settings": {...}
}

And the python

_json = json.load(file)
index = _json['index']
aliases = _json['aliases']
body = _json['body']

es.indices.create(index=index, body=body)
if len(aliases) > 0:
       for alias in aliases:
           es.indices.put_alias(index=index, name=alias)
Mitch Wilson
  • 109
  • 10
0

As the source code of elasticsearch-py says, the body argument of indices.create cannot include any aliases:

body: The configuration for the index (settings and mappings)

With that being said, there are other methods in that library that enable you to create aliases.

Joe - GMapsBook.com
  • 15,787
  • 4
  • 23
  • 68