I'm trying to perform a GET request to elastic search api which is needed in this form
GET /_search
{
"query": {
"more_like_this" : {
"fields" : ["title", "description"],
"like" : "Once upon a time",
"min_term_freq" : 1,
"max_query_terms" : 12
}
}
}
I used request But I can't find how to add body to the request.
Any help?
I'm trying to perform a GET request to elastic search api which is needed in this form
GET /_search
{
"query": {
"more_like_this" : {
"fields" : ["title", "description"],
"like" : "Once upon a time",
"min_term_freq" : 1,
"max_query_terms" : 12
}
}
}
I used request But I can't find how to add body to the request.
Any help?
Share Improve this question edited Jun 25, 2018 at 10:21 LucasSeveryn 6,3028 gold badges41 silver badges66 bronze badges asked Jun 25, 2018 at 9:56 abdoutelbabdoutelb 1,0531 gold badge15 silver badges34 bronze badges3 Answers
Reset to default 6You can see the document about request(options, callback)
Also, GET
method should't send any body, please confirm it's not POST
.
request.get('http://localhost:8092/_search', {
json: true,
body: {
"query": {
"more_like_this" : {
"fields" : ["title", "description"],
"like" : "Once upon a time",
"min_term_freq" : 1,
"max_query_terms" : 12
}
}
}
})
If you use GET
, you can't have body, you just have query.
You can convert your query to string and add to your url, or use option with qs
:
option = {
url: 'your_url',
qs: your_query
};
request(option, (error,res)=>{});
If want use body, you should use POST
.
You can not add body to a get request, you will have to add a query string for the request to send those data.