my es version:6.4
my question: My nested query is in the first should, but looking at the document that inner_hit hits the second should, what should I do to make nested only hit the first should, the inner_hit I expect is empty, in a query
my index
PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"user": {
"type": "nested"
}
}
}
}
}
my mapping
{
"mapping": {
"_doc": {
"properties": {
"group": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"user": {
"type": "nested",
"properties": {
"first": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"last": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
my data
PUT my_index/_doc/1
{
"group" : "fans",
"user" : [
{
"first" : "John",
"last" : "Smith"
},
{
"first" : "Alice",
"last" : "White"
}
]
my dsl
{
"query":{
"bool":{
"should":[
{
"bool":{
"must":[
{
"nested":{
"query":{
"term":{
"user.first.keyword":{
"value":"John",
"boost":1
}
}
},
"path":"user",
"ignore_unmapped":false,
"score_mode":"none",
"boost":1,
"inner_hits":{
"ignore_unmapped":false,
"from":0,
"size":3,
"version":false,
"explain":false,
"track_scores":false
}
}
}
],
"must_not":[
{
"term":{
"group.keyword":{
"value":"fans",
"boost":1
}
}
}
],
"adjust_pure_negative":true,
"boost":1
}
},
{
"term":{
"group.keyword":{
"value":"fans",
"boost":1
}
}
}
],
"adjust_pure_negative":true,
"boost":1
}
}
}
actual results
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.2876821,
"hits": [
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_score": 0.2876821,
"_source": {
"group": "fans",
"user": [
{
"first": "John",
"last": "Smith"
},
{
"first": "Alice",
"last": "White"
}
]
},
"inner_hits": {
"user": {
"hits": {
"total": 1,
"max_score": 0.6931472,
"hits": [
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_nested": {
"field": "user",
"offset": 0
},
"_score": 0.6931472,
"_source": {
"first": "John",
"last": "Smith"
}
}
]
}
}
}
}
]
}
}
enter code here
My desired result is that inner_hit is empty, since the nested contained by the first should doesn't hit any documents