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 <[email protected]> * Apply text suggestions from code review Co-authored-by: kolchfa-aws <[email protected]> Signed-off-by: Destin <[email protected]> --------- Signed-off-by: Destin <[email protected]> Co-authored-by: kolchfa-aws <[email protected]>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user