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

Multi-level nesting fields problem #15

Closed
synweap15 opened this issue Aug 23, 2017 · 5 comments
Closed

Multi-level nesting fields problem #15

synweap15 opened this issue Aug 23, 2017 · 5 comments

Comments

@synweap15
Copy link

Hello!

First of all I'd like to thank the authors of this amazing library for all the effort - this library really helps when it comes to querying nested fields with ES' Query String Query.

I've found some issue concerning the parser when it comes to parsing multi-level nested fields (nested fields within nested fields).

Here's my definition of ElasticsearchQueryBuilder:

es_builder = ElasticsearchQueryBuilder(nested_fields={
        "study_units": {
            "country": {"id": {}, "name": {}}
    })

The query looks like this: study_units.country.name:italy

The produced output looks like this:

{
  'nested': {
    'query': {
      'nested': {
        'query': {
          'match': {
            'study_units.country.name': {
              'type': 'phrase',
              'query': 'italy',
              'zero_terms_query': 'none'
            }
          }
        },
        'path': 'study_units.country'
      }
    },
    'path': 'name'
  }
}

I think that the most outer path key should have the value of study_units instead of name.

My question - is this a problem with my definition of nested fields, or something is off here?

@synweap15
Copy link
Author

Figured it out - obviously I made a mistake taking some assumptions concerning Lucene syntax for nested fields. Did some reading and the query should be formulated as follows: study_units:(country:(name:italy)) - works like a charm!

@ahivert
Copy link
Contributor

ahivert commented Aug 23, 2017

You could write the query like this study_units:country:name:italy too :)

@synweap15
Copy link
Author

synweap15 commented Aug 23, 2017

Right, thanks @ahivert!

Another question: I have defined a few fields as Object types instead of Nested using elasticsearch-dsl, so they can be searched without explicitly specifying fields. The problem is that when I search using eg. country.name:Italy (not nested, just flattened, looks correct in Kibana), it's still treated as nested by Luqum - and then depending whether it was defined in nested_fields or not, I get RequestError for Elasticsearch or NestedSearchFieldException from _recurse_nested_fields.

Any hints?

@alexgarel
Copy link
Member

Hi @synweap15, indeed we did not have Object in mind when we decide to deal with nested field. Could you file a new ticket, possibly with expected behaviour ?

For now I close this ticket.

@synweap15
Copy link
Author

Sure, I'll open a new issue. Thanks!

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

3 participants