Hi all,
is it possible to get the count of all inner hits in a paginated query? If not, is there any alternative solution you can direct me to? I want to get the count of all items (segment.item) in the inner hits on the below sample mapping:
"mappings": {
"booking": {
"properties": {
"booking_number": {
"type": "text",
"analyzer": "ngram_analyzer",
"search_analyzer": "my_search_analyzer",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"segment": {
"type": "nested",
"properties": {
"start_date": {
"type": "date"
},
"end_date": {
"type": "date"
},
"cancel_timestamp": {
"type": "date"
},
"service": {
"type": "keyword"
},
"departure_station": {
"type": "keyword"
},
"arrival_station": {
"type": "keyword"
},
"multi_segment": {
"type": "boolean"
},
"item": {
"type": "nested",
"properties": {
"item_id": {
"type": "integer"
},
"inventory_class": {
"type": "keyword"
},
"carriage_number": {
"type": "keyword"
},
"product_code": {
"type": "keyword"
},
"product_type": {
"type": "keyword"
},
"ticket_number": {
"type": "keyword"
},
"cancel_timestamp": {
"type": "date"
},
"expiry_timestamp": {
"type": "date"
},
"validation": {
"type": "nested",
"properties": {
"type": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
}
my query:
curl -XGET 'localhost: 9200/bookings/booking/_search?pretty' -d '{
"size": 5,
"timeout": "60s",
"query": {
"bool": {
"filter": [{
"nested": {
"query": {
"bool": {
"filter": [{
"nested": {
"query": {
"bool": {
"must": [{
"exists": {
"field": "segment.item.ticket_number",
"boost": 1.0
}
},
{
"terms": {
"segment.item.product_type": ["ST",
"SO",
"TO"],
"boost": 1.0
}
}],
"must_not": [{
"exists": {
"field": "segment.item.expiry_timestamp",
"boost": 1.0
}
}],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"path": "segment.item",
"ignore_unmapped": false,
"score_mode": "sum",
"boost": 1.0,
"inner_hits": {
"name": "segment.item",
"ignore_unmapped": false,
"from": 0,
"size": 20,
"version": false,
"explain": false,
"track_scores": false
}
}
},
{
"range": {
"segment.start_date": {
"from": null,
"to": "2017-10-19",
"include_lower": true,
"include_upper": true,
"boost": 1.0
}
}
},
{
"range": {
"segment.end_date": {
"from": "2017-10-19",
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1.0
}
}
}],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"path": "segment",
"ignore_unmapped": false,
"score_mode": "sum",
"boost": 1.0,
"inner_hits": {
"name": "segment",
"ignore_unmapped": false,
"from": 0,
"size": 10,
"version": false,
"explain": false,
"track_scores": false,
"_source": false
}
}
}],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"_source": false
}