I am using the Elasticsearch-DSL Python client to create a new index that stores objects called IndexedDocument
that are subclasses of elasticsearch_dsl.Document
.
index_name = "my-index"
index = elasticsearch_dsl.Index(index_name)
IndexedDocument.init(index_name)
dict(index.get_settings())
{'my-index': {'settings': {'index': {'routing': {'allocation': {'include': {'_tier_preference': 'data_content'}}},
'number_of_shards': '1',
'provided_name': 'my-index',
'creation_date': '1699980696153',
'number_of_replicas': '1',
'uuid': '7dT2dzvjT0elqJ_APSUqHQ',
'version': {'created': '8500003'}}}}}
I want to add metadata to the index, a key called "my_key" with a value "my value" that I can read back from the index.
Here is what I have tried with Elasticsearch-DSL and the errors I've gotten.
index.put_settings(my_key="my value")
Traceback (most recent call last):
File "/Users/bill.mcneill/anaconda3/envs/Lingua/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3548, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-10-b032164530ed>", line 1, in <module>
index.put_settings(my_key="my value")
File "/Users/bill.mcneill/anaconda3/envs/Lingua/lib/python3.10/site-packages/elasticsearch_dsl/index.py", line 517, in put_settings
return self._get_connection(using).indices.put_settings(
File "/Users/bill.mcneill/anaconda3/envs/Lingua/lib/python3.10/site-packages/elasticsearch/_sync/client/utils.py", line 402, in wrapped
return api(*args, **kwargs)
TypeError: IndicesClient.put_settings() got an unexpected keyword argument 'my_key'
I also tried passing in dictionaries since that seems the most similar to what you do with the REST API.
index.put_settings({"my_key": "my value"})
Traceback (most recent call last):
File "/Users/bill.mcneill/anaconda3/envs/Lingua/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3548, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-11-ef4da1979ed6>", line 1, in <module>
index.put_settings({"my_key": "my value"})
File "/Users/bill.mcneill/anaconda3/envs/Lingua/lib/python3.10/site-packages/elasticsearch_dsl/index.py", line 517, in put_settings
return self._get_connection(using).indices.put_settings(
AttributeError: 'dict' object has no attribute 'indices'
I get the same error for index.put_settings({"index":{"my_key": "my value"}})
and index.put_settings({"settings":{"index":{"my_key": "my value"}}})
.
How do I do this?