Skip to content

Elasticsearch instrumentalization incorectly serializes object containing dots in field name #3034

Open
@imamatory

Description

Describe your environment

OS: OS X Sequoia 15.01
Python version: Python 3.11.7
Package version: 0.47b.0
Elasticsearch: 6

What happened?

For specific queries with both field names 'name' and 'name.morph' ElasticsearchInstrumentor creates the wrong db statement and breaks the original query object.

Steps to Reproduce

Form a request like this:

body = {
 'from': 0,
 'highlight': {'fields': {'name': {},
                                    'name.morph': {}}},
 'query': {'bool': {'filter': [{'terms': {'status': ['ACTIVE']}}]}},
 'size': 3}

Expected Result

Db statement (note fields key)

("{'from': 0, 'highlight': {'fields': {'name': {}, 'name.morph': {}}}, 'query': "
 "{'bool': {'filter': '?'}}, 'size': 3}")

Original body object:

{'from': 0,
 'highlight': {'fields': {'name': {'morph': {}},
                          'name.morph': {'morph': {}}}},
 'query': {'bool': {'filter': [{'terms': {'status': ['ACTIVE']}}]}},
 'size': 3}

Actual Result

Db statement (note fields key)

("{'from': 0, 'highlight': {'fields': {'name': {'morph': {...}}}}, 'query': "
 "{'bool': {'filter': '?'}}, 'size': 3}")

The original body object becomes:

{'from': 0,
 'highlight': {'fields': {'name': {'morph': <Recursion on dict with id=4366695936>},
                          'name.morph': {'morph': <Recursion on dict with id=4366695936>}}},
 'query': {'bool': {'filter': [{'terms': {'status': ['ACTIVE']}}]}},
 'size': 3}

This body object is impossible to serialize so it breaks further on query serialization stage

Additional context

sanitize_body function mutates the original body and this is not good by itself.

Would you like to implement a fix?

Yes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions