AggregationBuilders throws an error JsonGenerationException - java

I am using elasticsearch API (elasticsearch5.2.1.jar)to do the aggregation query as follows,
StatsAggregationBuilder statAggBuild = AggregationBuilders.stats("agg").field("ipAddress");
This returns the follows exception
{ "error" : "JsonGenerationException[Can not write a field name, expecting a value]"}
Am I doing anything wrong here ?

It is not causing any issue while setting this Object in the request. It returns the response as expected
It looks the actual problem exist in the toString method, Which throws the error when we try to look what exist in the project

Related

Can searchResponse.getHits().getHits(); throw nullpointer exception

We are getting a nullpointerexception at searchResponse.getHits().getHits();
I'm totally new to elastic search and don't know how it works but need to analyse this issue.
Let me know if it throws nullpointerexception in any case ?
If it throws how to handle this ?
Looking at the code of InternalSearchResponse, it looks like hits gets initialised with SearchHits.empty() even if the response is empty.
For the other cases, it always gets initialised with new. You can have a look at the source code here.
I had the same exception after an update from 7.4 to 7.17.
It seems that the hits variable of the internalResponse can be NULL, at least in 7.17.1 - could be related to HL request option ignoreUnavailable set to FALSE, and/or queering a no longer existing index.
searchResponse.getHits() can return NULL!

In integration test case in one scenario i want to add data inside of response.ok(returns java objects) to one obj..how can we do that

used this String output = response.readEntity(String.class); But getting IllegalStateException how to resolve this..getEntity(); is also throwing exception

Json Error in Eclipse stating Expected value at 1:0

I have a web application built on Spring Boot and running on a Tomcat 8.5 server. I am trying to create a json object in Eclipse which contains the information about the apis. But it throws an error stating: "Expected value at 1:0" The error gets resolved when I remove the object declaration.
Here the code to my url.json file.
URL = {
"FETCH_ALL_USER":"http://localhost:8080/rest/info/",
"SEND_LEAVE_REQUEST":"http://localhost:8080/rest/find"
}
Why do I get this error and how do I solve this.
We need to enclose the json property in double quotes. save and re-validate the file.
Visit -> JSON Parse Error: Expecting 'STRING'
solved this issue for me.

Objectify: Unable to evaluate the expression Method threw 'com.googlecode.objectify.LoadException' exception

i am learning how to store and retrieve data with the google app engine and objectify, and set up a test project in intellij-idea. i created a simple entity that looks like this:
ContactType
#Entity
public class ContactType {
#Id
public Long id;
public String name;
public ContactType(String name){
this.name = name;
}
}
before i start testing i delete all saved instances i created before in my servlet:
deleting old data
Objectify ofy = ObjectifyService.ofy();
ObjectifyService.register(ContactType.class);
List<Key<ContactType>> contactTypes = ofy.load().type(ContactType.class).keys().list();
ofy.delete().keys(contactTypes).now();
after that i save this entity like this:
saving new data
ContactType contactType1 = new ContactType("contactType1");
ContactType contactType2 = new ContactType("contactType2");
ofy.save().entity(contactType1 ).now();
ofy.save().entity(contactType2 ).now();
then i retrieve the objects i just saved like this:
retrieving data
List<ContactType> list= ofy
.load()
.type(ContactType.class)
.list();
and get the 2 expected objects.
but when i comment out the lines that delete and save the old entries, and just want to retrieve the entries that i saved last time (and which i can still see in the development console), and inspect the returned entries with the intellij-idea debugger, i just get this small error message and no stacktrace in the console at all.:
debugging error message
Unable to evaluate the expression Method threw 'com.googlecode.objectify.LoadException' exception.
and when i change the "view as" option from "list" to "toString" in the intellij-idea debugger i get only following information:
so my questions are:
how can i save and retrieve data with objectify?
how can i see a detailed error stacktrace when something goes wrong?
i finally fixed this problem. when i try to get the size of the returned list and put a try/catch around it then i get an error message that my entity does not have a default constructor without parameters.
try{
List<ContactType> list= ofy
.load()
.type(ContactType.class)
.list();
int size = list.size();
}catch(LoadException e){
String message = e.getMessage();
}
after adding following construtor everything works fine:
public ContactType(){
name = "";
}
In answer to part 2 of your question, the stacktrace thrown by Objectify includes all the information you need in the wrapped exception. Whatever is catching and logging the exception is apparently suppressing the exception message. This is not default behavior of the GAE dev environment, so I don't know what's going on.

solrj Error from server invalid number

I'm trying to write some data from my java application to solr using solrj.
I can query the solr server fine, but whenever I try to write some data to the server I get an error of invalid number, even when I'm writing a string to a string field.
Sample code to reproduce the error:
public class solrdocimport {
public static void main(String[] args) throws MalformedURLException, SolrServerException, IOException {
SolrClient client = new HttpSolrClient("http://192.168.175.136:8983/solr/nsf");
SolrInputDocument solrDoc = new SolrInputDocument();
solrDoc.addField("Subject", "Hello", 1.0f);
client.add(solrDoc);
}
}
The field "Subject" exists in the schema and it is defined as a String field, however the error I get is invalid number?
I've search around an cannot find anything in relation to this error. Does anyone know how to I can write to the solr server?
Sounds you might have some automatic ID generation in solrconfig.xml and then you changed your id field in schema.xml to be a number. Try changing id back to string, since you are not using it and see if the problem goes away.

Categories

Resources