I'm using elasticsearch 5.0.0, and I've got three indexes which I'm trying to query and get data through my code. I'm sending a post request which includes a json body as well. It returns a 400 when when I'm running my code, but then when I just copy and pasted the url in the browser it return the results properly.
The code perfectly works when I tried using elasticsearch 2.3.5 and the it returns the data properly. I just couldn't find where am I going wrong. I checked the elasticsearch log as well, and there's no errors as such.
Could it be the version difference? Here is my code to send the post request:
public JSONObject getResult(String query, String elasticSearchIndex, String body) throws IOException, JSONException {
if (query != null) {
URL mUrl = new URL(getElasticSearchQueryUrlForEmptyQuery(query, elasticSearchIndex));
HttpURLConnection conn = (HttpURLConnection) mUrl.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
String input = body;
OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();
BufferedReader inputStream = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = inputStream.readLine()) != null) {
response.append(inputLine);
}
return new JSONObject(response.toString());
}
return null;
}
In the above I'm sending the json body for the request from another class.
When your project "discuss" with the new version 5.0.0, It may uses the new version of Elasticsearch API.
Somewhere in your project your have defined the Elasticsearch client version. You have to find this configuration,
maybe in a pom.xml or in you /lib/ directory, and replace with the 5.0.0 version.
What I found was this. According to this I changed my aggs and it's working once I recreated the index using a PUT and then tried pushing data to that index.
Once I query, it's working now. But then without recreating the whole thing is there any way I could insert the "fielddata": true for the existing index I've got at the moment?
If it's a string value I can do this and get the results. But for some fields which are actually string in the db and I need to convert them to either double or int in elasticsearchaggs before I get the results.
I sent a PUT request in order to create the index with the following body:
Currently I'm doing the below in order to convert string to int for the field (chargeamount) but then, in the result (chargeamount) still shows as a string value where as it should be a double. How can I define it within the aggs or within the mappings when I'm creating the index?
You have pushed a new Mapping version and reindexed your datas to a new index having this mapping ?
The exception seems to say that it tries to convert the double into a String, so the field seems to be a double.
I thought I was trying to give a double type of mapping for the field so that I can directly get the value automatically converted from string to double. So the exception comes from the first scenario when I do this:
I haven't specified any but as I remember I made the change script.inline: on in my elasticsearch.yml. Seems like groovy has been deprecated in v5.0.0 with painless. So which means I've got to mention "lang": "painless" within the script?
@xavierfacq It was my mistake, I had a logstash conversion within the mutate filter in order to convert the field into double. I commented it out and tried with the existing configurations, it worked.
For whomever it might help. So had this is as my mapping:
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.