Skip to content

Parent/Child and Nested field support for query_string queries #16551

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

Open
drush opened this issue Feb 9, 2016 · 36 comments
Open

Parent/Child and Nested field support for query_string queries #16551

drush opened this issue Feb 9, 2016 · 36 comments
Labels
>enhancement high hanging fruit :Search Relevance/Search Catch all for Search Relevance Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch

Comments

@drush
Copy link

drush commented Feb 9, 2016

I am requesting that query_string queries be able to specify parent fields as part of the query_string query. This should not cause any scaling challenges as parent-child mapping ensures that both documents will be located on the same shard, the syntax is well supported for nested data, and this is an intuitive use case for parent mappings.

Currently there are two terrible ways to return Children based on search criteria for Parents:

  1. use the has_parent query construct - fine if you are able to build a single query use case, but virtually unusable if you are providing functionality to a user-facing search UI and leveraging query_string
  2. nest the parent metadata into the each child - defeats the whole purpose of parent-child mapping, and requires every child to be updated anytime a parent record changes

If there is some technical reason this cannot be accomplished, please advise. If this is a feature others could use, please leave a +1 to get this issue some attention.

Thanks,
D

@andrewvc
Copy link
Contributor

andrewvc commented Feb 9, 2016

+1 .

I'm wondering about the complexity here. AFAIK the query string query is a Lucene feature exposed by ES, and parent/child is ES only. I'm not sure what the technical implications of doing this would be, since I think it would require moving the query string syntax code into the ES core, which IIRC is in Lucene core ATM.

@Raydius
Copy link

Raydius commented Feb 9, 2016

+1 definitely helpful

@mabeller
Copy link

mabeller commented Feb 9, 2016

+1

1 similar comment
@dotnetallday
Copy link

+1

@clintongormley clintongormley changed the title FEATURE REQUEST: parent.field query support for query_string queries Parent/Child and Nested field support for query_string queries Feb 13, 2016
@clintongormley
Copy link
Contributor

I've updated the title to include access to nested fields (originally requested in #11322).

What I'd be interested in seeing is what the query string syntax would look like for accessing parent/child/nested docs.

@drush
Copy link
Author

drush commented Feb 19, 2016

@clintongormley I think the syntax would be exactly as it is for Inner Objects which use simple dot-notation to reference deeper elements of the indexed JSON source. The root field should be the name of the parent type, so let's say you have Company and Employee types, where Company is parent to the Employee, I should be able to query:

/index/Employee/_search
... { query_string: "name:bob* AND Company.location:Boston AND Company.employees.women:>=15" }

In this contrived example, location is a field of the parent Company type, and employees.women is a inner object of the Company type. Name is a field of the Employee type.

query_string queries already support inner field/nested object query specifiers via dot-notation.

I have reviewed #11322 and Nested Documents are a significantly different use case than 'inner fields' which is the reference I intended to make in my intro. The largest difference is that the parent will always be a has_one type relationship to the child - which means that there isn't some type of document reduction necessary to calculate score, etc - as appears may be the case in the nested document scenario.

So, to keep the complexity and effort for this case low, I'd suggest not to co-mingle it with the potentially more challenging Nested Documents scenario.

@Alex1sz
Copy link

Alex1sz commented Feb 25, 2016

+1

@bipin-nag
Copy link

+1

@rmm5t
Copy link

rmm5t commented Sep 19, 2016

What I'd be interested in seeing is what the query string syntax would look like for accessing parent/child/nested docs.

Chiming in here to reiterate my comment from #11322 (comment)

Overall, I'd really just like to see an ability to narrow a query string search to one particular embedded object. I'd like to see a syntax that looked like this:

children:(gender:male AND age:>=18 AND age:<=25)

Otherwise, there's no way to use the query string syntax and (in this particular US-centric example) find parents who have children who should be signed up for the US Selective Service System.

@jefyjiang
Copy link

+1

16 similar comments
@mihir83in
Copy link

+1

@kchudinov
Copy link

+1

@Jackalx
Copy link

Jackalx commented Jan 4, 2017

+1

@anosulchik
Copy link

+1

@OleksandrObidniak
Copy link

+1

@dnetrebenko-smartling
Copy link

+1

@nibum2001
Copy link

+1

@mrkamel
Copy link

mrkamel commented Feb 10, 2017

+1

@macks22
Copy link

macks22 commented Mar 3, 2017

+1

@prasadkhandagale
Copy link

+1

@tmpace
Copy link

tmpace commented Apr 20, 2017

+1

@madirey
Copy link

madirey commented May 9, 2017

+1

@daniel-keller
Copy link

+1

@nirajpatel
Copy link

+1

@EricPSU
Copy link

EricPSU commented Aug 15, 2017

+1

@casper1149
Copy link

+1

@imranansarij2ee
Copy link

+1

@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Query DSL labels Feb 14, 2018
@andyb-elastic
Copy link
Contributor

@elastic/es-search-aggs

@jimczi
Copy link
Contributor

jimczi commented Jun 4, 2018

We discussed internally and agreed that it's something that we'd like to have.
A syntax like the one proposed in #16551 (comment) would be great:
children:(gender:male AND age:>=18 AND age:<=25)
However it is not possible to handle this kind of customization in the current query string query parser which depends on the Lucene's query parser. I marked this issue as an high hanging fruit to emphasize the complexity of the feature but there are simple things that we can do in the meantime to mitigate the need:

  • We can rewrite simple individual clause to the correct nested query. e.g.foo.bar:this AND foo.bar:that would match parent documents that have a child document with foo.bar:this and another child document with foo.bar:that. That would not solve the entire issue but it would be nicer that returning no document at all.
  • It seems that the feature is highly needed for Kibana because query_string is/was the only way to build a full text query. Now that Kibana has its own query language I wonder how difficult it would be to handle nested queries there. @Bargs do you think this is something that can be added in Kuery ?

@Bargs
Copy link

Bargs commented Jun 12, 2018

Yeah nested support is something we've wanted to add to kuery, but we just haven't had time for yet.

@kennyshittu
Copy link

+1

@rjernst rjernst added the Team:Search Meta label for search team label May 4, 2020
@denisburlacu
Copy link

+1

@cawoodm
Copy link
Contributor

cawoodm commented Sep 3, 2021

So if we use nested objects we can sort on sub-objects but not search them with a query_string.
And if we use normal sub-objects we can search them with a query_string but not sort the result.

So the options are:

  • Use nested options and drop query_string searches OR
  • Duplicate sub-objects as nested objects to get the best of both worls

@lasiltan
Copy link

I have a schema with a lot of object arrays. Being able to index them as nested objects and then have support for nested queries in the query_string query would really make my day. Or support them in KQL and allow ES queries with KQL.

@NickPadilla
Copy link

This issue hasn't been touched in a while and i suspect that there hasn't been enough interest in this feature to make it a priority. However, I do think that having support for nested fields via lucene syntax is a big deal. I would love to see this feature, we will need to support sorting on sub-objects. Right now the only way to accomplish this is to use Nested types.

I guess, as an alternative for my use case.. is there a way support sorting on sub-object fields? If so then our use case would be solved.

@javanna javanna added :Search Relevance/Search Catch all for Search Relevance and removed :Search/Search Search-related issues that do not fall into other categories labels Jul 17, 2024
@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Jul 17, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

@elasticsearchmachine elasticsearchmachine removed the Team:Search Meta label for search team label Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement high hanging fruit :Search Relevance/Search Catch all for Search Relevance Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch
Projects
None yet
Development

No branches or pull requests