question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug when calling Document.init() more than once

See original GitHub issue

Using

elasticsearch==6.3.1
elasticsearch-dsl==6.2.1

Against an Elastic Search cluster: 6.3.2

Using this Document to persist data:

class Data(Document):
    some_field = Text()
    
    class Meta:
        doc_type = 'data_doc_type'
    
    class Index:
        name = 'data'
        doc_type = 'data_doc_type'
        settings = {
            "number_of_shards": 60,
            "number_of_replicas": 1
        }

When i call init Data.init() for the first time it actually works ok and creates the index and mapping correctly within ElasticSearch, but when i need to call it again to apply new mapping to that index i come accross this exception:

File "data.py", line ***, in init
    Data.init()
  File "elasticsearch_dsl/document.py", line 128, in init
    i.save(using=using)
  File "elasticsearch_dsl/index.py", line 260, in save
    self.put_settings(using=using, body=settings)
  File "elasticsearch_dsl/index.py", line 430, in put_settings
    return self._get_connection(using).indices.put_settings(index=self._name, **kwargs)
  File "elasticsearch/client/utils.py", line 76, in _wrapped
    return func(*args, params=params, **kwargs)
  File "elasticsearch/client/indices.py", line 547, in put_settings
    '_settings'), params=params, body=body)
  File "elasticsearch/transport.py", line 318, in perform_request
    status, headers_response, data = connection.perform_request(method, url, params, body, headers=headers, ignore=ignore, timeout=timeout)
  File "elasticsearch/connection/http_requests.py", line 90, in perform_request
    self._raise_error(response.status_code, raw_data)
  File "elasticsearch/connection/base.py", line 125, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)

And this is the actual reponse from elastic:

{
    "error": {
        "root_cause": [
            {
                "type": "remote_transport_exception",
                "reason": "[1-*****][x.x.x.x:9300][indices:admin/settings/update]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Can't update non dynamic settings [[index.number_of_shards]] for open indices [[data/***]]"
    },
    "status": 400
}

The problem seems to be that you’re trying to apply the settings more than once to settings that are not writable.

The problem is that in now i don’t know how to just update the mapping on that index.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hoIIercommented, Mar 26, 2020

@HonzaKral I just ran into this exact issue on latest when I mistakenly thought Post.init() was idempotent. Is this supposed to be fixed?

Is it safe to do this instead?

if not index := Index('posts').exists():
    Post.init()

I received error:

RequestError(400, 'illegal_argument_exception', "Can't update non dynamic settings [[index.number_of_shards]] for open indices [[posts-staging/sOmqF5m3RymtcVj2-2vflA]]")
elasticsearch==7.6.0
elasticsearch-dsl==7.1.0
1reaction
honzakralcommented, Nov 19, 2018

I provided a hotfix in a991fae, I will add some more tests around the functionality and, while this is not a guaranteed solution for all settings, for your use case this should now be fixed with the next release that should be coming soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python RuntimeError: Can not call init more than once
I think the issue is that you are calling json_logging.init twice. I know the second line is different but it may still not...
Read more >
The 10 Most Common JavaScript Issues Developers Face
If you need help figuring out why your JavaScript isn't working, consult this list of the 10 most common JavaScript issues from a...
Read more >
Bug descriptions — spotbugs 4.7.3 documentation
This document lists the standard bug patterns reported by SpotBugs. ... identity is based on criteria more complicated than simple reference equality.).
Read more >
Top 10 JavaScript errors from 1000+ projects (and ... - Rollbar
1. Uncaught TypeError: Cannot read property ... If you're a JavaScript developer, you've probably seen this error more than you care to admit....
Read more >
Initialization, Finalization, and Threads — Python 3.11.1 ...
The following functions should not be called before Py_Initialize() ... happen if an application calls Py_Initialize() and Py_FinalizeEx() more than once.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found