The query results is different via kibana console and python api

Hi,
when I using Query DSL in kibana console:

GET newtest/_search
{
  "query":{
    "terms":{"_id":["abcdefghij"]}
  }
}

I got:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_index" : "newtest",
"_type" : "newtest",
"_id" : "abcdefghij",
"_score" : 1.0,
"_source" : {
"field1" : "testtesttest",
"field2" : {
"try1" : "n/a",
"hahaha" : "123",
"abc" : {
"Cluster0" : {
"F" : "1",
"Num" : "8"
}
},
"Date" : "20170516"
},
"Result" : {
"ggg" : "69",
"kfx" : "40",
"yxe" : "57",
"1ee3r" : "52"
}
}
}
]
}
}

and using elasticsearch-py :

  res = _ES.search( index = newtest, body = {
        "query": {
            "terms": {
            "_id": ["abcdefghij"]
        }
    }
})
print res['hits']
return res['hits']

I got:
{u'_score': 1.0,
u'_type': u'newtest',
u'_id': u'abcdefghij',
u'_source': {
u'field2': {
u'Date': u'20170516',
u'abc': {
u'Cluster0': {
u'Num': u'8',
u'F': u'1'
}
},
u'try1': u'n/a',
u'hahaha': u'123'
},
u'field1': u'testtesttest',
u'Result': {
u'ggg': u'69',
u'1ee3r': u'52',
u'kfx': u'40',
u'yxe': u'57'
}
},
u'_index': u'newtest'
}

the return fields order between two methods are not the same at all,
how to do to get the same order's result?

There's only one result. What do you want to sort?
The source field is not modified by elasticsearch when it comes back.
I think it's more a python print issue here.
Just print the response object as a string if possible.

Hi,

Your problem is not because you read a dict?

Hi @dadoonet and @gabriel_tessier,

thanks for your reply to let me realize the problem is caused by python datatype,
so it will become random order to the fields.

I find the similar problem in elasticsearch-py:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.