Correct nested.md example (#4352)

* Update nested.md

Update nested.md with a query examples that showcase nested features as intended.

Signed-off-by: Destin <8732109+destinf@users.noreply.github.com>

* Apply text suggestions from code review

Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com>
Signed-off-by: Destin <8732109+destinf@users.noreply.github.com>

---------

Signed-off-by: Destin <8732109+destinf@users.noreply.github.com>
Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com>
This commit is contained in:
Destin 2023-06-27 06:11:40 +08:00 committed by GitHub
parent 3527245634
commit 0b859900a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 109 additions and 2 deletions

View File

@ -172,11 +172,118 @@ PUT testindex1/_doc/100
```
{% include copy-curl.html %}
Now if you run the same query to search for patients older than 75 AND smokers, nothing is returned, which is correct.
You can use the following nested query to search for patients older than 75 OR smokers:
```json
GET testindex1/_search
{
"query": {
"nested": {
"path": "patients",
"query": {
"bool": {
"should": [
{
"term": {
"patients.smoker": true
}
},
{
"range": {
"patients.age": {
"gte": 75
}
}
}
]
}
}
}
}
}
```
{% include copy-curl.html %}
The query correctly returns both patients:
```json
{
"took" : 3,
"took" : 7,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.8465736,
"hits" : [
{
"_index" : "testindex1",
"_id" : "100",
"_score" : 0.8465736,
"_source" : {
"patients" : [
{
"name" : "John Doe",
"age" : 56,
"smoker" : true
},
{
"name" : "Mary Major",
"age" : 85,
"smoker" : false
}
]
}
}
]
}
}
```
You can use the following nested query to search for patients older than 75 AND smokers:
```json
GET testindex1/_search
{
"query": {
"nested": {
"path": "patients",
"query": {
"bool": {
"must": [
{
"term": {
"patients.smoker": true
}
},
{
"range": {
"patients.age": {
"gte": 75
}
}
}
]
}
}
}
}
}
```
{% include copy-curl.html %}
The previous query returns no results, as expected:
```json
{
"took" : 7,
"timed_out" : false,
"_shards" : {
"total" : 1,