# The query results is different via kibana console and python api

**URL:** <https://discuss.elastic.co/t/the-query-results-is-different-via-kibana-console-and-python-api/171245>\
**Category:** Elasticsearch\
**Created:** [March 7, 2019, 7:36am UTC](https://discuss.elastic.co/t/the-query-results-is-different-via-kibana-console-and-python-api/171245 "2019-03-07T07:36:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chely](https://avatars.discourse-cdn.com/v4/letter/c/ba9def/32.png) [@chely](https://discuss.elastic.co/u/chely)\
**Post date:** [March 7, 2019, 7:36am UTC](https://discuss.elastic.co/t/the-query-results-is-different-via-kibana-console-and-python-api/171245/1 "2019-03-07T07:36:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 7, 2019, 7:54am UTC](https://discuss.elastic.co/t/the-query-results-is-different-via-kibana-console-and-python-api/171245/2 "2019-03-07T07:54:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [March 7, 2019, 7:59am UTC](https://discuss.elastic.co/t/the-query-results-is-different-via-kibana-console-and-python-api/171245/3 "2019-03-07T07:59:57Z")

</div>

Hi,

Your problem is not because you read a dict?

---

<div class="post-metadata">

**Author:** ![chely](https://avatars.discourse-cdn.com/v4/letter/c/ba9def/32.png) [@chely](https://discuss.elastic.co/u/chely)\
**Post date:** [March 7, 2019, 9:41am UTC](https://discuss.elastic.co/t/the-query-results-is-different-via-kibana-console-and-python-api/171245/4 "2019-03-07T09:41:56Z")

</div>

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:

> <https://github.com/elastic/elasticsearch-py/issues/68>

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 4, 2019, 9:42am UTC](https://discuss.elastic.co/t/the-query-results-is-different-via-kibana-console-and-python-api/171245/5 "2019-04-04T09:42:02Z")

</div>

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