Python JSON - Elasticsearch - [_na] query malformed, must start with start_object












0















I am trying to duplicate the following json params in a Python post request:



enter image description here



This is what I have in my dictionary:



payload = {
'match':{'situs.state':'AL'},
'notMatch':{},
'page':1,
'range':{
'loanAmount':[
{
'gte':None,
'lte':10000000
}
]
},
'size':100
}


I then pass this dictionary into my post request with json.dumps so it gets converted to json and sent with the post request.




data = json.dumps(payload)




However, nothing works as I get the following error:




{"type":"Elasticsearch","message":"[parsing_exception] [_na] query
malformed, must start with start_object, with { line=1 & col=119
}","path":"/some_path","query":{"size":100,"from":0},"statusCode":400,"body":{"error":{"root_cause":[{"type":"parsing_exception","reason":"[_na]
query malformed, must start with
start_object","line":1,"col":119}],"type":"parsing_exception","reason":"[_na]
query malformed, must start with
start_object","line":1,"col":119},"status":400}}




Where am I going wrong here?










share|improve this question

























  • 0 should be gte and 1 should be lte

    – Val
    Nov 22 '18 at 17:29











  • I am new to json. I just quickly checked out what gte and lte are. After replacing them (I've also editted my initial post to reflect the changes) and running the code again, I now get :"type": "parsing_exception","reason":"[range] query doesn't support multiple fields, found [loanAmount] and [lte]"

    – curiousgeorge
    Nov 22 '18 at 17:44


















0















I am trying to duplicate the following json params in a Python post request:



enter image description here



This is what I have in my dictionary:



payload = {
'match':{'situs.state':'AL'},
'notMatch':{},
'page':1,
'range':{
'loanAmount':[
{
'gte':None,
'lte':10000000
}
]
},
'size':100
}


I then pass this dictionary into my post request with json.dumps so it gets converted to json and sent with the post request.




data = json.dumps(payload)




However, nothing works as I get the following error:




{"type":"Elasticsearch","message":"[parsing_exception] [_na] query
malformed, must start with start_object, with { line=1 & col=119
}","path":"/some_path","query":{"size":100,"from":0},"statusCode":400,"body":{"error":{"root_cause":[{"type":"parsing_exception","reason":"[_na]
query malformed, must start with
start_object","line":1,"col":119}],"type":"parsing_exception","reason":"[_na]
query malformed, must start with
start_object","line":1,"col":119},"status":400}}




Where am I going wrong here?










share|improve this question

























  • 0 should be gte and 1 should be lte

    – Val
    Nov 22 '18 at 17:29











  • I am new to json. I just quickly checked out what gte and lte are. After replacing them (I've also editted my initial post to reflect the changes) and running the code again, I now get :"type": "parsing_exception","reason":"[range] query doesn't support multiple fields, found [loanAmount] and [lte]"

    – curiousgeorge
    Nov 22 '18 at 17:44
















0












0








0








I am trying to duplicate the following json params in a Python post request:



enter image description here



This is what I have in my dictionary:



payload = {
'match':{'situs.state':'AL'},
'notMatch':{},
'page':1,
'range':{
'loanAmount':[
{
'gte':None,
'lte':10000000
}
]
},
'size':100
}


I then pass this dictionary into my post request with json.dumps so it gets converted to json and sent with the post request.




data = json.dumps(payload)




However, nothing works as I get the following error:




{"type":"Elasticsearch","message":"[parsing_exception] [_na] query
malformed, must start with start_object, with { line=1 & col=119
}","path":"/some_path","query":{"size":100,"from":0},"statusCode":400,"body":{"error":{"root_cause":[{"type":"parsing_exception","reason":"[_na]
query malformed, must start with
start_object","line":1,"col":119}],"type":"parsing_exception","reason":"[_na]
query malformed, must start with
start_object","line":1,"col":119},"status":400}}




Where am I going wrong here?










share|improve this question
















I am trying to duplicate the following json params in a Python post request:



enter image description here



This is what I have in my dictionary:



payload = {
'match':{'situs.state':'AL'},
'notMatch':{},
'page':1,
'range':{
'loanAmount':[
{
'gte':None,
'lte':10000000
}
]
},
'size':100
}


I then pass this dictionary into my post request with json.dumps so it gets converted to json and sent with the post request.




data = json.dumps(payload)




However, nothing works as I get the following error:




{"type":"Elasticsearch","message":"[parsing_exception] [_na] query
malformed, must start with start_object, with { line=1 & col=119
}","path":"/some_path","query":{"size":100,"from":0},"statusCode":400,"body":{"error":{"root_cause":[{"type":"parsing_exception","reason":"[_na]
query malformed, must start with
start_object","line":1,"col":119}],"type":"parsing_exception","reason":"[_na]
query malformed, must start with
start_object","line":1,"col":119},"status":400}}




Where am I going wrong here?







python json elasticsearch post python-requests






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 18:59







curiousgeorge

















asked Nov 22 '18 at 17:22









curiousgeorgecuriousgeorge

417




417













  • 0 should be gte and 1 should be lte

    – Val
    Nov 22 '18 at 17:29











  • I am new to json. I just quickly checked out what gte and lte are. After replacing them (I've also editted my initial post to reflect the changes) and running the code again, I now get :"type": "parsing_exception","reason":"[range] query doesn't support multiple fields, found [loanAmount] and [lte]"

    – curiousgeorge
    Nov 22 '18 at 17:44





















  • 0 should be gte and 1 should be lte

    – Val
    Nov 22 '18 at 17:29











  • I am new to json. I just quickly checked out what gte and lte are. After replacing them (I've also editted my initial post to reflect the changes) and running the code again, I now get :"type": "parsing_exception","reason":"[range] query doesn't support multiple fields, found [loanAmount] and [lte]"

    – curiousgeorge
    Nov 22 '18 at 17:44



















0 should be gte and 1 should be lte

– Val
Nov 22 '18 at 17:29





0 should be gte and 1 should be lte

– Val
Nov 22 '18 at 17:29













I am new to json. I just quickly checked out what gte and lte are. After replacing them (I've also editted my initial post to reflect the changes) and running the code again, I now get :"type": "parsing_exception","reason":"[range] query doesn't support multiple fields, found [loanAmount] and [lte]"

– curiousgeorge
Nov 22 '18 at 17:44







I am new to json. I just quickly checked out what gte and lte are. After replacing them (I've also editted my initial post to reflect the changes) and running the code again, I now get :"type": "parsing_exception","reason":"[range] query doesn't support multiple fields, found [loanAmount] and [lte]"

– curiousgeorge
Nov 22 '18 at 17:44














1 Answer
1






active

oldest

votes


















1














The range part should be like this:



     'range':{
'loanAmount':{
'gte':None,
'lte':10000000
}
},





share|improve this answer
























  • After looking around I saw that its just as you said. I was passing two arguments instead of one. However, I need loanAmount to remain as an array and not a dict. Running the code with loanAmount as an dictionary crashes with a TypeError: unhashable type: 'dict'. I've revised my code to reflect the changes and my new error.

    – curiousgeorge
    Nov 22 '18 at 18:34






  • 1





    Aside from that your payload is just not a valid DSL query. notMatch and page are not valid and match and range need to be inside a bool query. I'm not sure how you came to that query format

    – Val
    Nov 22 '18 at 19:02













  • I came to that query format from not knowing anything about Elasticsearch, like literally nothing. I thought I just had to replicate plain json with my post request. I wasn't aware there was a specific format I had to follow. That explains a lot! Well, I guess I'm off to learn exactly what Elasticsearch is and how to write a proper query. Thanks @Val!

    – curiousgeorge
    Nov 22 '18 at 19:21











  • Awesome, glad it helped!

    – Val
    Nov 22 '18 at 19:34











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435788%2fpython-json-elasticsearch-na-query-malformed-must-start-with-start-objec%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The range part should be like this:



     'range':{
'loanAmount':{
'gte':None,
'lte':10000000
}
},





share|improve this answer
























  • After looking around I saw that its just as you said. I was passing two arguments instead of one. However, I need loanAmount to remain as an array and not a dict. Running the code with loanAmount as an dictionary crashes with a TypeError: unhashable type: 'dict'. I've revised my code to reflect the changes and my new error.

    – curiousgeorge
    Nov 22 '18 at 18:34






  • 1





    Aside from that your payload is just not a valid DSL query. notMatch and page are not valid and match and range need to be inside a bool query. I'm not sure how you came to that query format

    – Val
    Nov 22 '18 at 19:02













  • I came to that query format from not knowing anything about Elasticsearch, like literally nothing. I thought I just had to replicate plain json with my post request. I wasn't aware there was a specific format I had to follow. That explains a lot! Well, I guess I'm off to learn exactly what Elasticsearch is and how to write a proper query. Thanks @Val!

    – curiousgeorge
    Nov 22 '18 at 19:21











  • Awesome, glad it helped!

    – Val
    Nov 22 '18 at 19:34
















1














The range part should be like this:



     'range':{
'loanAmount':{
'gte':None,
'lte':10000000
}
},





share|improve this answer
























  • After looking around I saw that its just as you said. I was passing two arguments instead of one. However, I need loanAmount to remain as an array and not a dict. Running the code with loanAmount as an dictionary crashes with a TypeError: unhashable type: 'dict'. I've revised my code to reflect the changes and my new error.

    – curiousgeorge
    Nov 22 '18 at 18:34






  • 1





    Aside from that your payload is just not a valid DSL query. notMatch and page are not valid and match and range need to be inside a bool query. I'm not sure how you came to that query format

    – Val
    Nov 22 '18 at 19:02













  • I came to that query format from not knowing anything about Elasticsearch, like literally nothing. I thought I just had to replicate plain json with my post request. I wasn't aware there was a specific format I had to follow. That explains a lot! Well, I guess I'm off to learn exactly what Elasticsearch is and how to write a proper query. Thanks @Val!

    – curiousgeorge
    Nov 22 '18 at 19:21











  • Awesome, glad it helped!

    – Val
    Nov 22 '18 at 19:34














1












1








1







The range part should be like this:



     'range':{
'loanAmount':{
'gte':None,
'lte':10000000
}
},





share|improve this answer













The range part should be like this:



     'range':{
'loanAmount':{
'gte':None,
'lte':10000000
}
},






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 18:16









ValVal

103k6138173




103k6138173













  • After looking around I saw that its just as you said. I was passing two arguments instead of one. However, I need loanAmount to remain as an array and not a dict. Running the code with loanAmount as an dictionary crashes with a TypeError: unhashable type: 'dict'. I've revised my code to reflect the changes and my new error.

    – curiousgeorge
    Nov 22 '18 at 18:34






  • 1





    Aside from that your payload is just not a valid DSL query. notMatch and page are not valid and match and range need to be inside a bool query. I'm not sure how you came to that query format

    – Val
    Nov 22 '18 at 19:02













  • I came to that query format from not knowing anything about Elasticsearch, like literally nothing. I thought I just had to replicate plain json with my post request. I wasn't aware there was a specific format I had to follow. That explains a lot! Well, I guess I'm off to learn exactly what Elasticsearch is and how to write a proper query. Thanks @Val!

    – curiousgeorge
    Nov 22 '18 at 19:21











  • Awesome, glad it helped!

    – Val
    Nov 22 '18 at 19:34



















  • After looking around I saw that its just as you said. I was passing two arguments instead of one. However, I need loanAmount to remain as an array and not a dict. Running the code with loanAmount as an dictionary crashes with a TypeError: unhashable type: 'dict'. I've revised my code to reflect the changes and my new error.

    – curiousgeorge
    Nov 22 '18 at 18:34






  • 1





    Aside from that your payload is just not a valid DSL query. notMatch and page are not valid and match and range need to be inside a bool query. I'm not sure how you came to that query format

    – Val
    Nov 22 '18 at 19:02













  • I came to that query format from not knowing anything about Elasticsearch, like literally nothing. I thought I just had to replicate plain json with my post request. I wasn't aware there was a specific format I had to follow. That explains a lot! Well, I guess I'm off to learn exactly what Elasticsearch is and how to write a proper query. Thanks @Val!

    – curiousgeorge
    Nov 22 '18 at 19:21











  • Awesome, glad it helped!

    – Val
    Nov 22 '18 at 19:34

















After looking around I saw that its just as you said. I was passing two arguments instead of one. However, I need loanAmount to remain as an array and not a dict. Running the code with loanAmount as an dictionary crashes with a TypeError: unhashable type: 'dict'. I've revised my code to reflect the changes and my new error.

– curiousgeorge
Nov 22 '18 at 18:34





After looking around I saw that its just as you said. I was passing two arguments instead of one. However, I need loanAmount to remain as an array and not a dict. Running the code with loanAmount as an dictionary crashes with a TypeError: unhashable type: 'dict'. I've revised my code to reflect the changes and my new error.

– curiousgeorge
Nov 22 '18 at 18:34




1




1





Aside from that your payload is just not a valid DSL query. notMatch and page are not valid and match and range need to be inside a bool query. I'm not sure how you came to that query format

– Val
Nov 22 '18 at 19:02







Aside from that your payload is just not a valid DSL query. notMatch and page are not valid and match and range need to be inside a bool query. I'm not sure how you came to that query format

– Val
Nov 22 '18 at 19:02















I came to that query format from not knowing anything about Elasticsearch, like literally nothing. I thought I just had to replicate plain json with my post request. I wasn't aware there was a specific format I had to follow. That explains a lot! Well, I guess I'm off to learn exactly what Elasticsearch is and how to write a proper query. Thanks @Val!

– curiousgeorge
Nov 22 '18 at 19:21





I came to that query format from not knowing anything about Elasticsearch, like literally nothing. I thought I just had to replicate plain json with my post request. I wasn't aware there was a specific format I had to follow. That explains a lot! Well, I guess I'm off to learn exactly what Elasticsearch is and how to write a proper query. Thanks @Val!

– curiousgeorge
Nov 22 '18 at 19:21













Awesome, glad it helped!

– Val
Nov 22 '18 at 19:34





Awesome, glad it helped!

– Val
Nov 22 '18 at 19:34


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435788%2fpython-json-elasticsearch-na-query-malformed-must-start-with-start-objec%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'