Hi, everyone
I'm trying to retrieve only matching elements from array like this:
{
"speed": 2.24,
"incident": "RIGHT_TURN",
"timestamp": "2018-03-06 15:38:19.454",
"geoposition": {
"coordinates": [
19.145480869745988,
50.27426389026141
],
"type": "point"
}
},
{
"speed": 2.97,
"incident": "LEFT_TURN",
"timestamp": "2018-03-06 15:38:17.456",
"geoposition": {
"coordinates": [
19.145461604945485,
50.2742377011437
],
"type": "point"
}
},
{
"speed": 3.73,
"incident": "LEFT_TURN",
"timestamp": "2018-03-06 15:38:16.457",
"geoposition": {
"coordinates": [
19.145437295613323,
50.27423723030056
],
"type": "point"
}
elements are mapped to nested.
I want to search only those which have for example incident == "LEFT_TURN" is there any chance to do that and if it is how can I do that in NEST
I'm trying to do this like that:
{
"_source": "incidents.incident",
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"nested": {
"path": "incidents",
"query": {
"bool": {
"must": {
"match": { "incidents.incident" : "LEFT_TURN" }
}
}
}
}
}
}
}
}
but the result is:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "sltracks1",
"_type": "elastictrack",
"_id": "2",
"_score": 1,
"_source": {
"incidents": [
{
"incident": "LEFT_TURN"
},
{
"incident": "RIGHT_TURN"
},
{
"incident": "RIGHT_TURN"
},
{
"incident": "RIGHT_TURN"
},
{
"incident": "RIGHT_TURN"
},
{
"incident": "RIGHT_TURN"
},
{
"incident": "LEFT_TURN"
},
{
"incident": "LEFT_TURN"
},
{
"incident": "LEFT_TURN"
},
{
"incident": "LEFT_TURN"
},
{
"incident": "LEFT_TURN"
},
{
"incident": "LEFT_TURN"
},
{
"incident": "LEFT_TURN"
},
{
"incident": "LEFT_TURN"
},
{
"incident": "LEFT_TURN"
},
{
"incident": "LEFT_TURN"
}
]
}
}
]
}
}
best regards
Piotr