elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.61k stars 24.64k forks source link

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

Open drush opened 8 years ago

drush commented 8 years ago

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 commented 8 years ago

+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 commented 8 years ago

+1 definitely helpful

mabeller commented 8 years ago

+1

dotnetallday commented 8 years ago

+1

clintongormley commented 8 years ago

I've updated the title to include access to nested fields (originally requested in https://github.com/elastic/elasticsearch/issues/11322).

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

drush commented 8 years ago

@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 commented 8 years ago

+1

bipin-nag commented 8 years ago

+1

rmm5t commented 8 years ago

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 https://github.com/elastic/elasticsearch/issues/11322#issuecomment-248093863

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 commented 7 years ago

+1

mihir83in commented 7 years ago

+1

kchudinov commented 7 years ago

+1

Jackalx commented 7 years ago

+1

anosulchik commented 7 years ago

+1

OleksandrObidniak commented 7 years ago

+1

dnetrebenko-smartling commented 7 years ago

+1

nibum2001 commented 7 years ago

+1

mrkamel commented 7 years ago

+1

macks22 commented 7 years ago

+1

prasadkhandagale commented 7 years ago

+1

tmpace commented 7 years ago

+1

madirey commented 7 years ago

+1

daniel-keller commented 7 years ago

+1

nirajpatel commented 7 years ago

+1

EricPSU commented 7 years ago

+1

casper1149 commented 6 years ago

+1

imranansarij2ee commented 6 years ago

+1

andyb-elastic commented 6 years ago

@elastic/es-search-aggs

jimczi commented 6 years ago

We discussed internally and agreed that it's something that we'd like to have. A syntax like the one proposed in https://github.com/elastic/elasticsearch/issues/16551#issuecomment-248095564 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:

Bargs commented 6 years ago

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

kennyshittu commented 4 years ago

+1

denisburlacu commented 3 years ago

+1

cawoodm commented 3 years ago

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:

lasiltan commented 2 years ago

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 commented 7 months ago

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.

elasticsearchmachine commented 2 months ago

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