Jax-rs rest api using stored template


#1

Hi,

I'm trying to figure how I can create a jax-rs REST call to search elastic search using a stored template.
for the moment I'm doing a POST , using the http body to put the data in. Somehting like this :

POST http://1.2.3.4:9200/index/type/_search/template

and as a body :
{
"file": "count",
"params": {
"grp_by_field": "objecttype.keyword"
}
}

where count is the moustache file. Is this correct ? This works in jmeter, but I'm getting a http 400 status back when
executing this using jax-rs :
String queryString="{ "file": "count" , "params": { "grp_by_field"="objecttype.keyword" } }";

	Response r = client
			.target("http://1.2.3.4:9200")
			.path("/index/type/_search/template")
			.request(MediaType.APPLICATION_JSON)
			.post(Entity.json(queryString)); 

In any case, it doesn't feel right to do a POST when querying data... Any ideas on how to do this ?

tnx,
Chris


#2

ok, now it works, it was not grp_by_field= but grp_by_field:

remains the question that : is it correct to the use the api like this : submitting a post to execute a query ?


(David Pilato) #3

It's better to use a GET indeed as we state in the documentation: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html

That said, some libraries don't support GET with body. That's why we support in that case both GET and POST verbs.


#4

ok tnx !


(system) #5

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