Hello -
I am trying to execute a query which has match query (nodeid)+ sort(with date) + size(1). I am trying to get the out N curries the latest requried nodeid details. And this cscfcounter index will be getting updated for every 60sec.
curl -X GET "localhost:9200/cscfcounter/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {"match" : {"NodeId" : "swevmware-cscf02"}},
"sort":[{"date" : {"order" : "desc"}}],
"size" : 1
}'
But when i execute , i am getting the output with a different nodeid i.e "swevmware-cscf01". Even though i made it swevmware-cscf02.
curl -X GET "localhost:9200/cscfcounter/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {"match" : {"NodeId" : "swevmware-cscf02"}},
"sort":[{"date" : {"order" : "desc"}}],
"size" : 1
}'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 38558,
"max_score" : null,
"hits" : [
{
"_index" : "cscfcounter",
"_type" : "cscfcounter",
"_id" : "AWO18thxI4ct1UZkHTaN",
"_score" : null,
"_source" : {
"CpuAverageLoad" : 1,
"HaGroupId" : "100001",
"LbGroupId" : "",
"MemFree" : 100,
"MemUsed" : 0,
"NodeId" : "swevmware-cscf01",
"NodeType" : "cscf",
"State" : "online",
"Static_limit" : 0,
"date" : "2018-05-31T11:26:21.296747036Z"
},
"sort" : [
1527765981296
]
}
]
}
}
But if execute the same command with size 2, then i am getting the both nodeid i.e cscf01 & cscf02.
curl -X GET "localhost:9200/cscfcounter/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {"match" : {"NodeId" : "swevmware-cscf02"}},
"sort":[{"date" : {"order" : "desc"}}],
"size" : 2
}'
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 38562,
"max_score" : null,
"hits" : [
{
"_index" : "cscfcounter",
"_type" : "cscfcounter",
"_id" : "AWO1876pI4ct1UZkHTaU",
"_score" : null,
"_source" : {
"CpuAverageLoad" : 1,
"HaGroupId" : "100001",
"LbGroupId" : "",
"MemFree" : 100,
"MemUsed" : 0,
"NodeId" : "swevmware-cscf01",
"NodeType" : "cscf",
"State" : "online",
"Static_limit" : 0,
"date" : "2018-05-31T11:27:20.23261639Z"
},
"sort" : [
1527766040232
]
},
{
"_index" : "cscfcounter",
"_type" : "cscfcounter",
"_id" : "AWO187lJI4ct1UZkHTaT",
"_score" : null,
"_source" : {
"CpuAverageLoad" : 0,
"HaGroupId" : "100001",
"LbGroupId" : "",
"MemFree" : 100,
"MemUsed" : 0,
"NodeId" : "swevmware-cscf02",
"NodeType" : "cscf",
"State" : "online",
"Static_limit" : 0,
"date" : "2018-05-31T11:27:18.855816443Z"
},
"sort" : [
1527766038855
]
}
]
}
}
I doubt when we sort by date with size1 it is taking the latest updated doc in that index.