Indexing AVRO Documents

Hi

I have a code to read AVRO that iterates over records and builds the XContentBuilder
object from it and indexes it.
I have introduced a code for Auto-Classification that accepts the record as
XContentBuilder.string() and retruns a String with Catagories in it.

XContentBuilder jBuilder = jsonBuilder().startObject();

jBuilder.field("data",input);
String s=a.addCategory(jBuilder.string());
jBuilder.field("tags", s);// line 3
Now I am trying to add the catagories to XContentBuilder object (line 3)
before indexing it but have the following exception thrown:

org.elasticsearch.common.jackson.core.JsonGenerationException: Can not
write a field name, expecting a value
how do i resolve this issue?

Thanks

Kuwar Sahani

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Can you post all your code?
I mean that I don't see any endObject() method call.
What is the content of s? Could it be null?

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 15 avr. 2013 à 11:40, kuwar sahani kuwarsahani@gmail.com a écrit :

Hi

I have a code to read AVRO that iterates over records and builds the XContentBuilder object from it and indexes it.
I have introduced a code for Auto-Classification that accepts the record as XContentBuilder.string() and retruns a String with Catagories in it.

XContentBuilder jBuilder = jsonBuilder().startObject();

jBuilder.field("data",input);
String s=a.addCategory(jBuilder.string());
jBuilder.field("tags", s);// line 3

Now I am trying to add the catagories to XContentBuilder object (line 3) before indexing it but have the following exception thrown:

org.elasticsearch.common.jackson.core.JsonGenerationException: Can not write a field name, expecting a value
how do i resolve this issue?

Thanks

Kuwar Sahani

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

hi
unable to attach a file somehow.
writing a demo code.

public class AutoClassification {

public String addCategory(String input) {

String next;
List categories = new ArrayList();
try{
BufferedReader inputReader = new BufferedReader(new FileReader(
"D:/kuwar/w2/Auto Classification/Dictionary.txt"));
while((next=inputReader.readLine())!=null){
if(input.contains(next)){
categories.add("""+next+""");
}

}
}
catch (Exception e) {

}

return categories.toString();
}
public static void main(String args) throws IOException {
AutoClassification a= new AutoClassification();
XContentBuilder jBuilder = jsonBuilder().startObject();
String input="XYZ is an IT company.it has launched the product in BIG
DATA Space";
jBuilder.field("data",input);
String s=a.addCategory(jBuilder.bytesStream().toString());
System.out.println(s);
//s =["IT","XYZ"]
//the error is thrown here:
jBuilder.field("tags", s);
jBuilder.endObject();
System.out.println(jBuilder.string());
}
}

On Monday, 15 April 2013 15:24:43 UTC+5:30, David Pilato wrote:

Can you post all your code?
I mean that I don't see any endObject() method call.
What is the content of s? Could it be null?

-- 

David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfrhttps://twitter.com/elasticsearchfr
| @scrutmydocs https://twitter.com/scrutmydocs

Le 15 avr. 2013 à 11:40, kuwar sahani <kuwar...@gmail.com <javascript:>>
a écrit :

Hi

I have a code to read AVRO that iterates over records and builds the XContentBuilder
object from it and indexes it.
I have introduced a code for Auto-Classification that accepts the record
as XContentBuilder.string() and retruns a String with Catagories in it.

XContentBuilder jBuilder = jsonBuilder().startObject();

jBuilder.field("data",input);
String s=a.addCategory(jBuilder.string());
jBuilder.field("tags", s);// line 3
Now I am trying to add the catagories to XContentBuilder object (line 3)
before indexing it but have the following exception thrown:

org.elasticsearch.common.jackson.core.JsonGenerationException: Can not
write a field name, expecting a value
how do i resolve this issue?

Thanks

Kuwar Sahani

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Use GIST to post your code.

If you need to add an array to your json (using jsonbuilder), use startArray() and endArray() instead of try to build a String like "["IT","XYZ"]" and put that in a tag.

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 15 avr. 2013 à 12:04, kuwar sahani kuwarsahani@gmail.com a écrit :

hi
unable to attach a file somehow.
writing a demo code.

public class AutoClassification {

public String addCategory(String input) {

String next;
List categories = new ArrayList();
try{
BufferedReader inputReader = new BufferedReader(new FileReader(
"D:/kuwar/w2/Auto Classification/Dictionary.txt"));
while((next=inputReader.readLine())!=null){
if(input.contains(next)){
categories.add("""+next+""");
}

}
}
catch (Exception e) {

}

return categories.toString();
}
public static void main(String args) throws IOException {
AutoClassification a= new AutoClassification();
XContentBuilder jBuilder = jsonBuilder().startObject();
String input="XYZ is an IT company.it has launched the product in BIG DATA Space";
jBuilder.field("data",input);
String s=a.addCategory(jBuilder.bytesStream().toString());
System.out.println(s);
//s =["IT","XYZ"]
//the error is thrown here:
jBuilder.field("tags", s);
jBuilder.endObject();
System.out.println(jBuilder.string());
}
}

On Monday, 15 April 2013 15:24:43 UTC+5:30, David Pilato wrote:
Can you post all your code?
I mean that I don't see any endObject() method call.
What is the content of s? Could it be null?

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 15 avr. 2013 à 11:40, kuwar sahani kuwar...@gmail.com a écrit :

Hi

I have a code to read AVRO that iterates over records and builds the XContentBuilder object from it and indexes it.
I have introduced a code for Auto-Classification that accepts the record as XContentBuilder.string() and retruns a String with Catagories in it.

XContentBuilder jBuilder = jsonBuilder().startObject();

jBuilder.field("data",input);
String s=a.addCategory(jBuilder.string());
jBuilder.field("tags", s);// line 3

Now I am trying to add the catagories to XContentBuilder object (line 3) before indexing it but have the following exception thrown:

org.elasticsearch.common.jackson.core.JsonGenerationException: Can not write a field name, expecting a value
how do i resolve this issue?

Thanks

Kuwar Sahani

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

once you call the .string() method of an XContentBuilder object, it does
not allow to add another field to it, leave aside the data type to be added.

On Monday, 15 April 2013 16:47:18 UTC+5:30, David Pilato wrote:

Use GIST to post your code.

If you need to add an array to your json (using jsonbuilder), use
startArray() and endArray() instead of try to build a String like
"["IT","XYZ"]" and put that in a tag.

-- 

David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfrhttps://twitter.com/elasticsearchfr
| @scrutmydocs https://twitter.com/scrutmydocs

Le 15 avr. 2013 à 12:04, kuwar sahani <kuwar...@gmail.com <javascript:>>
a écrit :

hi
unable to attach a file somehow.
writing a demo code.

public class AutoClassification {

public String addCategory(String input) {

String next;
List categories = new ArrayList();
try{
BufferedReader inputReader = new BufferedReader(new FileReader(
"D:/kuwar/w2/Auto Classification/Dictionary.txt"));
while((next=inputReader.readLine())!=null){
if(input.contains(next)){
categories.add("""+next+""");
}

}
}
catch (Exception e) {

}

return categories.toString();
}
public static void main(String args) throws IOException {
AutoClassification a= new AutoClassification();
XContentBuilder jBuilder = jsonBuilder().startObject();
String input="XYZ is an IT company.it has launched the product in BIG
DATA Space";
jBuilder.field("data",input);
String s=a.addCategory(jBuilder.bytesStream().toString());
System.out.println(s);
//s =["IT","XYZ"]
//the error is thrown here:
jBuilder.field("tags", s);
jBuilder.endObject();
System.out.println(jBuilder.string());
}
}

On Monday, 15 April 2013 15:24:43 UTC+5:30, David Pilato wrote:

Can you post all your code?
I mean that I don't see any endObject() method call.
What is the content of s? Could it be null?

-- 

David Pilato | Technical Advocate | *Elasticsearch.comhttp://elasticsearch.com/
*
@dadoonet https://twitter.com/dadoonet | @elasticsearchfrhttps://twitter.com/elasticsearchfr
| @scrutmydocs https://twitter.com/scrutmydocs

Le 15 avr. 2013 à 11:40, kuwar sahani kuwar...@gmail.com a écrit :

Hi

I have a code to read AVRO that iterates over records and builds the XContentBuilder
object from it and indexes it.
I have introduced a code for Auto-Classification that accepts the record
as XContentBuilder.string() and retruns a String with Catagories in it.

XContentBuilder jBuilder = jsonBuilder().startObject();

jBuilder.field("data",input);
String s=a.addCategory(jBuilder.string());
jBuilder.field("tags", s);// line 3
Now I am trying to add the catagories to XContentBuilder object (line 3)
before indexing it but have the following exception thrown:

org.elasticsearch.common.jackson.core.JsonGenerationException: Can not
write a field name, expecting a value
how do i resolve this issue?

Thanks

Kuwar Sahani

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.