-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Add inner hits to nested and parent/child queries #8153
Conversation
03419f3
to
4bc2ddd
Compare
documents or child document are returned based on matches in parent documents. In the nested case documents are returned | ||
based on matches in nested inner objects. | ||
|
||
In both cases the actual matches in the different scopes what caused a document to be returned is hidden. In many cases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/what/that/ ?
==== Options | ||
|
||
Inner hits support the following options: | ||
* `path` - Defines the nested scope where hits will be collected from. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it needs a line break here otherwise the documentation is not rendered correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, better to lay this out as:
[horizontal]
`path`:: Defines the nested scope where hits will be collected from.
`type`:: Defines the parent or child type score where hits will be collected from.
etc
This is a nice feature, but i was asking myself how is the inner documents returned. Is it returned by stream reading the source or a desieralization process or is there some kind of index behind the inner docs. The main reason i am asking this is because i have some very large nested documents and i don't know if returning inner docs his a wise solution in term of performance. Thank you |
@mathieu007 It deserialises the _source and retrieves the relevant inner json objects from the _source. The deserialisation is done only once per top level hit, so that shouldn't affect performance too much. Also if you are concerned about this you can enable stored fields inside nested inner objects in the mapping, that way the _source isn't touched at all and the field values for each returned inner hit can simply be fetched from disk. If you go down this path you may not need to |
@jpountz @dadoonet @clintongormley I updated the PR with the docs feedback. |
@martijnvg are we sold on the idea of specifying inner hits within the If we go for specifying within the query/filter, then I'd probably add a section on inner hits to the |
@clintongormley Yes, specifying the |
Is it possible to do global sorting based on inner hits doc filed ? |
@noter That is possible via nested sorting: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_sorting_within_nested_objects |
Yes thats clear but i was thinking about parent/child docs. |
Ok, sorting by fields in a child / parent document still needs to be implemented. The best workaround is to transform the value you'd like to sort by to a number based value and wrap a |
4ff7cf0
to
590930b
Compare
590930b
to
09238e3
Compare
I updated the PR to be in sync with the recent changes in master. |
09238e3
to
86ebcf5
Compare
@martijnvg Just an idea, it would be great if the returned data could be the inner hits + all it's parents, something like that:
|
@martijnvg, thanks. Has this work be slated for a particular release yet? |
@portante , it has v1.5 label on it :) |
Can you access inner hits from scripts? (sort or script fields) |
Hi, has this feature of inner hits been implemented in ES Java API? |
@aminakhan85 Yes, from version 1.5 on the nested, has_child and has_parent query/filter there is a new method with the name |
@martijnvg. Thanks for the info. Right now im using version 1.4. Ill upgrade to 1.5 and will check it out. Thanks |
Hello, looks like 1.5 official release is not available . When is it expected to be available? the latest I could find is 1.4.2 |
@aminakhan85 There is no date set on a release yet, but I expect it to be released in the coming months. |
Hi there, if my understanding of this new feature is correct: If a document with four objects in a nested field is queried and only objects 1 and 3 match, this will allow us to exclude objects 2 and 4 from the results and pull back only 1 and 3 as part of the 'inner_objects' field. Does that sound correct? |
(I think you meant 1 and 3 instead of 1 and 2 being returned?) On 21 January 2015 at 15:17, Aamir Latif [email protected] wrote:
Met vriendelijke groet, Martijn van Groningen |
Indeed yes, that's exactly what I meant - I updated my edited answer to that but you ended up responding to the email! Thanks a lot 👍 That's a great feature to have. |
Just been trying this out (built from the head of the 1.x branch), looks great, really useful. Quick bug report (don't want to raise a new issue for this as the feature isn't released yet, but will raise one if you think I should): if using a 'nested' type and you specify your child document as an object rather than an array, you get a classcast. i.e. your doc looks like this {
"nested_field": {
"make": "ford"
}
} When searching you will get a classcast like this:
You can fix it by giving the child as an array, but I think that either the nested hits stuff should support this single child, or it should throw an error when you try to index a document using that syntax. I'm also interested to know what the rules are for constructing the query that goes in the 'inner_hits' section? |
@tstibbs Great to hear you're trying it out! This looks like a bug, so can you open issue for it? All options defined here can be defined on a Beyond that it is also possible to define a top level Top level |
The much-anticipated feature |
I have an issue with usage of inner_hits. Version 1.7.1
This gives me inner_hits for the styles that are result of the second part of "or" (name: cutout color: white) but not for the styles that are result of the the first "or" query (name: embellished color: black). All the hits for the first or query are 0. If I reverse the first and second query in "or" there are inner_hits for query (name: embellished color: black) but not for (name: cutout color: white). I am not sure why this happens. ISs my query wrong? |
@bkuraku both your inner hits are using
|
@clintongormley Thanks. That worked like a charm!! |
V 1.7.1
When I do this I only get inner hits of products1 and always the vendors1 hits are 0. There are matching only because of vendorId attribute. Even in that case the inner_hits are in products1 and not in vendors1. Is this expected behavior? |
@bkuraku Providing just a query without the related mapping and document makes it pretty hard to debug what you're doing. Given that your previous issue was resolved by changing the document structure, I'd suggest asking the full question in the forum first: http://discuss.elastic.co/ Then, if the result of the discussion in the forum indicates that this is a bug, have a look at existing open issues, eg: If you don't find anything related, then open a new issue with a full recreation |
Inner hits allows to embed nested inner objects, children documents or the parent document that contributed to the matching of the returned search hit as inner hits, which would otherwise be hidden.
Example search request w/ nested query:
Example response:
For documentation and more examples check the:
inner-hits.asciidoc
file.Closes #3022, #3152