我正在使用elasticsearch將查詢發佈到json中,並且應該按照標準順序進行,否則結果將會出錯。問題是python正在改變我的json排序。我原來的json查詢是。在python映射對象中排序json
x= {
"query": {
"filtered": {
"query": {
"query_string": {
"query": "*a*"
}
},
"filter": {
"and": {
"filters": [
{
"term": {
"city": "london"
}
},
{
"term": {
"industry.industry_not_analyed": "oil"
}
}
]
}
}
}
},
"facets": {
"industry": {
"terms": {
"field": "industry.industry_not_analyed"
}
},
"city": {
"terms": {
"field": "city.city_not_analyzed"
}
}
}
}
但生成的python對象如下。
{
'query': {
'filtered': {
'filter': {
'and': {
'filters': [
{
'term': {
'city': 'london'
}
},
{
'term': {
'industry.industry_not_analyed': 'oil'
}
}
]
}
},
'query': {
'query_string': {
'query': '*a*'
}
}
}
},
'facets': {
'city': {
'terms': {
'field': 'city.city_not_analyzed'
}
},
'industry': {
'terms': {
'field': 'industry.industry_not_analyed'
}
}
}
}
結果與我所需要的不同,我該如何解決這個問題。
哪個版本的Python? –
我的Python版本是2.7.5 – Sar009
[Python字典,保持鍵/值的順序與聲明相同]的可能重複(http://stackoverflow.com/questions/1867861/python-dictionary-keep-keys-values-in聲明同樣的順序) –