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

[Elasticsearch] Convert two nested fields with the same path under same bool.must condition #268

Open
jkabat opened this issue May 29, 2019 · 3 comments

Comments

@jkabat
Copy link
Contributor

jkabat commented May 29, 2019

I'm trying to convert following string input to ES query and is very possible that this is not supported yet, however you might have an idea how to use RS to get it done.

String input:

"(width: 500 ~ 600; height: 1800;)"

Fieldset definition:

$generator->registerField('height', 'attributes[].height');
$generator->registerField('width', 'attributes[].width');

Query snippet:

{"bool":{"must":[
    {"nested":{..}}, 
    {"nested":{..}}
]}}

Would be possible to create one nested condition with queries inside bool? Something like:

{"bool":{"must":[
    {"nested":{
      "path":"attributes",
      "query":{"bool": {"must": [
           {"range":{"attributes.width":{"gte":500,"lte":600}}},
           {"terms":{"attributes.height":["1800"]}}
      ]}}

Unfortunately documentation is incomplete but there may exist a way to do a conversion by custom field, value+query transformer or simply by change of mapping in fieldset definition.
Is there something I may have missed?

@dkarlovi
Copy link
Contributor

As noted in the mails we exchanged:

About your question, your config looks correct and it should work just like you described since it's in the same group, referencing the same path. I'd say this is a bug and it's currently not possible to do with nested, but we do it for has_child queries.

If you check the tests for the has_child merge example, you can probably reproduce your example as one of those tests there in a PR. That would allow somebody (maybe even you!) to supply the implementation, which would be awesome for everybody.

@jkabat
Copy link
Contributor Author

jkabat commented May 29, 2019

@dkarlovi has_child seems to be working but it is not an option for me at the moment. As soon as I have time I'll take a look on grouping of nested type.

@dkarlovi
Copy link
Contributor

@jkabat I didn't mean you should change your query to has_child, I just meant the same principle done for has_child should be applied to nested. 👍

jkabat added a commit to jkabat/search that referenced this issue Jun 5, 2019
sstok added a commit that referenced this issue Jun 5, 2019
…bat)

This PR was merged into the 2.0-dev branch.

Discussion
----------

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | #268 
| License       | MIT
| Doc PR        | 

Follow up to #268 

Current implementation merges only single level nested fields (eg: author[].first_name, author[].last_name), not multiple level ones (item[].author[].name...). 

@dkarlovi Any thoughts how this can be solved? Merging is not working for HAS_CHILD queries with multiple levels as well. 

As this PR solves my current requirement I'm fine with single level fix, but I agree that complete solution is preferred. Unit test covering multiple level nesting case is included but failing... can be removed later.

Commits
-------

1cf8cd9 bug #268 fix: merge single level nested queries with the same path
@sstok sstok added this to the 2.0 milestone Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants