Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document for index produces error to get rid of deprecated message for body causes error #1839

Closed
ingmarthompson1964 opened this issue Dec 14, 2021 · 3 comments

Comments

@ingmarthompson1964
Copy link

ingmarthompson1964 commented Dec 14, 2021

Describe the feature:

Elasticsearch version 7.15

elasticsearch-py version (elasticsearch.__versionstr__): 7.15.2

Please make sure the major version matches the Elasticsearch server you are running.

Description of the problem including expected versus actual behavior:
I am getting this deprecated message when running a python script in 7.15.2. It says...

/mnt/isilon/SCRIPTS/bin/ICD10Import.py:347: DeprecationWarning: The 'body' parameter is deprecated for the 'index' API and will be removed in a future version. Instead use the 'document' parameter. See #1698 for more information

I have read the suggested URL, and it says to replace body with document in the code as in...

if not es.indices.exists(index="adn"):
        response = es.indices.create(
            index="adn",
            # body=icd10adn,
            document=icd10adn,
            #mappings=icd10adn,
            ignore=400  # ignore 400 already exists code
        )

When I do this, I get an error...

/mnt/isilon/opt/python/bin/python3 ICD10Import.py --feed TEST --log DEBUG
/mnt/isilon/SCRIPTS/bin/ICD10Import.py:310: DeprecationWarning: The 'body' parameter is deprecated for the 'create' API and will be removed in a future version. Instead use API parameters directly. See https://github.com/elastic/elasticsearch-py/issues/1698 for more information
  response = es.indices.create(
Traceback (most recent call last):
  File "/mnt/isilon/SCRIPTS/bin/ICD10Import.py", line 573, in <module>
    main()
  File "/mnt/isilon/SCRIPTS/bin/ICD10Import.py", line 317, in main
    response = es.indices.create(
  File "/mnt/isilon/opt/python/lib/python3.10/site-packages/elasticsearch/client/utils.py", line 301, in _wrapped
    return func(*args, params=params, headers=headers, **kwargs)
TypeError: IndicesClient.create() got an unexpected keyword argument 'document'
[ingmar@ip-172-31-30-59 bin]$ /mnt/isilon/opt/python/bin/python3 ICD10Import.py --feed TEST --log DEBUG
Traceback (most recent call last):
  File "/mnt/isilon/SCRIPTS/bin/ICD10Import.py", line 574, in <module>
    main()
  File "/mnt/isilon/SCRIPTS/bin/ICD10Import.py", line 310, in main
    response = es.indices.create(
  File "/mnt/isilon/opt/python/lib/python3.10/site-packages/elasticsearch/client/utils.py", line 301, in _wrapped
    return func(*args, params=params, headers=headers, **kwargs)
TypeError: IndicesClient.create() got an unexpected keyword argument 'document'

So the suggestion as stated in #1698 doesn't seem to work?
I saw another suggestion in https://discuss.elastic.co/ which said using mappings rather than body will get rid of the deprecated message such as

if not es.indices.exists(index="adn"):
        response = es.indices.create(
            index="adn",
            # body=icd10adn,
            # document=icd10adn,
            mappings=icd10adn,
            ignore=400  # ignore 400 already exists code
        )

Using this caused the same deprecated message to be displayed.

Steps to reproduce:

Take this python code...

if not es.indices.exists(index="alive"):
        # Note: i am not able to get the deprecated message to disappear.
        # The information at https://github.com/elastic/elasticsearch-py/issues/1698  is too vague for me to
        # understand how to code around not using the body key value.
        # load the alive index with settings and mappings
        #config_alive_index = load_json('../config/icd10alive.json')
        response = es.indices.create(
            index="alive",
            body=icd10alive,
            # document=icd10alive,
            # mappings=icd10alive,
            ignore=400  # ignore 400 already exists code
        )

get this message...

mnt/isilon/opt/python/bin/python3 ICD10Import.py --feed TEST --log DEBUG
/mnt/isilon/SCRIPTS/bin/ICD10Import.py:310: DeprecationWarning: The 'body' parameter is deprecated for the 'create' API and will be removed in a future version. Instead use API parameters directly. See https://github.com/elastic/elasticsearch-py/issues/1698 for more information

change the above code to

if not es.indices.exists(index="alive"):
        # Note: i am not able to get the deprecated message to disappear.
        # The information at https://github.com/elastic/elasticsearch-py/issues/1698  is too vague for me to
        # understand how to code around not using the body key value.
        # load the alive index with settings and mappings
        #config_alive_index = load_json('../config/icd10alive.json')
        response = es.indices.create(
            # index="alive",
            # body=icd10alive,
            document=icd10alive,
            # mappings=icd10alive,
            ignore=400  # ignore 400 already exists code
        )

and then I get this error...

Traceback (most recent call last):
  File "/mnt/isilon/SCRIPTS/bin/ICD10Import.py", line 573, in <module>
    main()
  File "/mnt/isilon/SCRIPTS/bin/ICD10Import.py", line 317, in main
    response = es.indices.create(
  File "/mnt/isilon/opt/python/lib/python3.10/site-packages/elasticsearch/client/utils.py", line 301, in _wrapped
    return func(*args, params=params, headers=headers, **kwargs)
TypeError: IndicesClient.create() got an unexpected keyword argument 'document'
[ingmar@ip-172-31-30-59 bin]$ /mnt/isilon/opt/python/bin/python3 ICD10Import.py --feed TEST --log DEBUG
Traceback (most recent call last):
  File "/mnt/isilon/SCRIPTS/bin/ICD10Import.py", line 574, in <module>
    main()
  File "/mnt/isilon/SCRIPTS/bin/ICD10Import.py", line 310, in main
    response = es.indices.create(
  File "/mnt/isilon/opt/python/lib/python3.10/site-packages/elasticsearch/client/utils.py", line 301, in _wrapped
    return func(*args, params=params, headers=headers, **kwargs)
TypeError: IndicesClient.create() got an unexpected keyword argument 'document'

If I change the code to use mappings such as

if not es.indices.exists(index="alive"):
        # Note: i am not able to get the deprecated message to disappear.
        # The information at https://github.com/elastic/elasticsearch-py/issues/1698  is too vague for me to
        # understand how to code around not using the body key value.
        # load the alive index with settings and mappings
        #config_alive_index = load_json('../config/icd10alive.json')
        response = es.indices.create(
            # index="alive",
            # body=icd10alive,
            # document=icd10alive,
             mappings=icd10alive,
            ignore=400  # ignore 400 already exists code
        )

It works, but I still get the deprecated message.
What do I need to add to the stated code block in the above to get rid of the deprecated message, since the provided solution in
#1698 doesn't seem to work to get rid of the message.

Thanks,
-Ingmar Thompson
Dish Network

@sethmlarson
Copy link
Contributor

Hello! Thanks for opening this issue. I'm seeing from your original DeprecationWarning message that you're potentially mixing up the index, create, and indices.create APIs. The DeprecationWarning mentions the index API but your examples are all using indices.create:

/mnt/isilon/SCRIPTS/bin/ICD10Import.py:347: DeprecationWarning: The 'body' parameter is deprecated for
the 'index' API and will be removed in a future version. Instead use the 'document' parameter.
See #1698 for more information

Make sure the line number in the DeprecationWarning is matching up with the API call you're modifying. For an example on how to use each of the above APIs without a DeprecationWarning see below:

# Index a document
es.index(
  index="alive",
  document={...}
)

# Create a document
es.create(
  index="alive",
  id="id",
  document={...}
)

# Create an index
es.indices.create(
  index="alive",
  mappings={...},
  ignore=400
)

Does this answer your question?

@sethmlarson
Copy link
Contributor

@ingmarthompson1964 Going to close this question as answered, let me know if this works for you.

@ingmarthompson1964
Copy link
Author

ingmarthompson1964 commented Dec 22, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants