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

fix elasticsearch get_schema error when mapping contains no 'properties' key #3692

Closed
wants to merge 3 commits into from

Conversation

truebit
Copy link

@truebit truebit commented Apr 10, 2019

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • New Query Runner (Data Source)
  • New Alert Destination
  • Other

Description

fix elasticsearch get_schema error when index has no 'properties' key.
This bug could be reproduced by trying to use a elasticsearch instance with .kibana index in it.

The version of Elasticsearch and Kibana I use is 5.6.3. Sample .kibana mappings or any other index which contains _default_ in mappings.

kibana_mappings.txt

I also added exception traceback print for future debugging purposes.

Related Tickets & Documents

#3570

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

no changes

@truebit
Copy link
Author

truebit commented Apr 10, 2019

This fix just fixes _default_ mappings in elasticsearch. for dynamic_templates, I cannot find a good way to achieve that.

…, it will raise error due to lack of key 'properties'
@truebit truebit changed the title fix elasticsearch get_schema error when index has no 'properties' key fix elasticsearch get_schema error when mapping contain no 'properties' key Apr 10, 2019
@truebit truebit changed the title fix elasticsearch get_schema error when mapping contain no 'properties' key fix elasticsearch get_schema error when mapping contains no 'properties' key Apr 10, 2019
@lomkju
Copy link

lomkju commented Apr 17, 2019

Thanks this helped us.

Copy link

@sunui sunui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job~

Copy link

@axelsean axelsean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get the elastic search.py to run on the docker image, the code below did work for me there

        if not 'properties' in doc:
            return result

@truebit
Copy link
Author

truebit commented May 8, 2019

@axelsean That's odd. Was that because doc variable is not a dict but a list in your scenario?

@axelsean
Copy link

axelsean commented May 9, 2019 via email

@truebit
Copy link
Author

truebit commented May 10, 2019

Could you debug it by printingdoc content to see what it is?

properties = doc.get('properties')
if not properties:
return result
for field, description in properties.items():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! What about making it a bit shorter and just writing this?

for field, description in doc.get('properties', {}).items():

Thus, there will be no need for previous new lines

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making python code short is a style thing, I am OK with that.
Besides, as latter comments pointed out, the doc may not be a dict. So maybe we still need code below to avoid the "not dict" issue.

if not isinstance(doc, dict):
    return result

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or

if not isinstance(doc, dict) or 'properties' not in doc:
    return result

and keep original code intact.

@aidarbek aidarbek assigned aidarbek and unassigned aidarbek May 14, 2019
@arikfr
Copy link
Member

arikfr commented Oct 27, 2019

Thank you for your effort on this and apologies that it wasn't merged eventually. Due to the state of the current implementation and the inability to properly test new changes, we decided to commit to making a new Elasticsearch query runner (#4293) and will address this and the other issues there.

@arikfr arikfr closed this Oct 27, 2019
@pavelpatrin pavelpatrin mentioned this pull request Nov 30, 2020
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants