Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elasticsearch DSL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Public
Elasticsearch DSL
Commits
61de50b9
Commit
61de50b9
authored
8 years ago
by
Mantas Marcinkevičius
Browse files
Options
Downloads
Patches
Plain Diff
added documentation for the nested inner hit
parent
8c469344
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/InnerHits/Nested.md
+111
-0
111 additions, 0 deletions
docs/InnerHits/Nested.md
with
111 additions
and
0 deletions
docs/InnerHits/Nested.md
0 → 100644
+
111
−
0
View file @
61de50b9
# Nested Inner Hits
> More info about inner hits is in the [official elasticsearch docs][1]
The nested inner_hits can be used to include nested inner objects as inner hits to a search hit.
The actual matches in the different scopes that caused a document to be returned is hidden.
In many cases, it’s very useful to know which inner nested objects caused certain information to be returned.
## Simple example
```
JSON
{
"query" : {
"nested" : {
"path" : "comments",
"query" : {
"match" : {"comments.message" : "[actual query]"}
}
}
},
"inner_hits" : {
"comment" : {
"path" : {
"comments" : {
"query" : {
"match" : {"comments.message" : "[different query]"}
}
}
}
}
}
}
```
And now the query via DSL:
```
php
$matchQuery
=
new
MatchQuery
(
'comments.message'
,
'[different query]'
);
$nestedQuery
=
new
NestedQuery
(
'comments'
,
$matchQuery
);
$innerHit
=
new
NestedInnerHit
(
'comment'
,
'comments'
,
$matchQuery
);
$search
=
new
Search
();
$search
->
addQuery
(
new
MatchQuery
(
'comments.message'
,
'[actual query]'
));
$search
->
addInnerHit
(
$innerHit
);
$search
->
toArray
();
```
In the example above
`comment`
is the name of the inner hit,
`comments`
is the path
to the nested field and
`$matchQuery`
is the actual query that will be executed.
## Nesting inner hits
It is possible to nest inner hits in order to reach deeper levels of nested objects.
Here is an example of nesting inner hits:
```
JSON
{
"inner_hits": {
"cars": {
"path": {
"cars": {
"query": {
"nested": {
"path": "cars.manufacturers",
"query": {
"match": {
"cars.manufacturers.country": {
"query": "Japan"
}
}
}
}
},
"inner_hits": {
"manufacturers": {
"path": {
"cars.manufacturers": {
"query": {
"match": {
"cars.manufacturers.country": {
"query": "Japan"
}
}
}
}
}
}
}
}
}
}
}
}
```
And now the query via DSL:
```
php
$matchQuery
=
new
MatchQuery
(
'cars.manufacturers.country'
,
'Japan'
);
$nestedQuery
=
new
NestedQuery
(
'cars.manufacturers'
,
$matchQuery
);
$innerHitNested
=
new
NestedInnerHit
(
'manufacturers'
,
'cars.manufacturers'
,
$matchQuery
);
$innerHit
=
new
NestedInnerHit
(
'cars'
,
'cars'
,
$nestedQuery
);
$innerHit
->
addInnerHit
(
$innerHitNested
);
$search
=
new
Search
();
$search
->
addInnerHit
(
$innerHit
);
$search
->
toArray
();
```
[
1
]:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment