I have sample documents like this at https://gist.github.com/663112,
and I am running a setting up specific fields to fetch using script
field like this for e.g. (through the java api)
{
"query" :{
"bool" : {
"should" : {"term" : {"_id" : 10990239 }},
"minimum_number_should_match" : 1
}
},
"script_fields" : {
"_id" : {
"script" : "_source._id"
},
"tags" : {
"script" : "_source.tags"
}
},
"size" : 5
}
Now after I perform the search I need to build my domain objects from
the returned data. I am doing something like this
for ( Map.Entry<String, SearchHitField> entry :
hit.getFields().entrySet() ) {
String fieldName = entry.getKey();
if ( fieldName.equals("tags") ) {
//do something with tags
LOG.debug("TAG VALUE = " +
entry.getValue().getValue());
} else {
//do something
}
}
Now the problem is entry.getValue().getValue() returns an Object, and
I have no way of manipulating that data. If I do a toString() on the
object value, I get the toString() version as
What you get back (in Java), is the "Map of Maps" representation of the json
(if you know jackson, then its the result of parsing the json into a map).
Its similar result as when calling sourceAsMap on a hit. You can use the
XContentFactory to get a jsonBuilder and write that map to get the json
representation of it.
I have sample documents like this at mock json · GitHub,
and I am running a setting up specific fields to fetch using script
field like this for e.g. (through the java api)
{
"query" :{
"bool" : {
"should" : {"term" : {"_id" : 10990239 }},
"minimum_number_should_match" : 1
}
},
"script_fields" : {
"_id" : {
"script" : "_source._id"
},
"tags" : {
"script" : "_source.tags"
}
},
"size" : 5
}
Now after I perform the search I need to build my domain objects from
the returned data. I am doing something like this
for ( Map.Entry<String, SearchHitField> entry :
hit.getFields().entrySet() ) {
String fieldName = entry.getKey();
if ( fieldName.equals("tags") ) {
//do something with tags
LOG.debug("TAG VALUE = " +
entry.getValue().getValue());
} else {
//do something
}
}
Now the problem is entry.getValue().getValue() returns an Object, and
I have no way of manipulating that data. If I do a toString() on the
object value, I get the toString() version as
What you get back (in Java), is the "Map of Maps" representation of the json
(if you know jackson, then its the result of parsing the json into a map).
Its similar result as when calling sourceAsMap on a hit. You can use the
XContentFactory to get a jsonBuilder and write that map to get the json
representation of it.
I have sample documents like this athttps://gist.github.com/663112,
and I am running a setting up specific fields to fetch using script
field like this for e.g. (through the java api)
{
"query" :{
"bool" : {
"should" : {"term" : {"_id" : 10990239 }},
"minimum_number_should_match" : 1
}
},
"script_fields" : {
"_id" : {
"script" : "_source._id"
},
"tags" : {
"script" : "_source.tags"
}
},
"size" : 5
}
Now after I perform the search I need to build my domain objects from
the returned data. I am doing something like this
for ( Map.Entry<String, SearchHitField> entry :
hit.getFields().entrySet() ) {
String fieldName = entry.getKey();
if ( fieldName.equals("tags") ) {
//do something with tags
LOG.debug("TAG VALUE = " +
entry.getValue().getValue());
} else {
//do something
}
}
Now the problem is entry.getValue().getValue() returns an Object, and
I have no way of manipulating that data. If I do a toString() on the
object value, I get the toString() version as
What you get back (in Java), is the "Map of Maps" representation of the
json
(if you know jackson, then its the result of parsing the json into a
map).
Its similar result as when calling sourceAsMap on a hit. You can use the
XContentFactory to get a jsonBuilder and write that map to get the json
representation of it.
I have sample documents like this athttps://gist.github.com/663112,
and I am running a setting up specific fields to fetch using script
field like this for e.g. (through the java api)
{
"query" :{
"bool" : {
"should" : {"term" : {"_id" : 10990239 }},
"minimum_number_should_match" : 1
}
},
"script_fields" : {
"_id" : {
"script" : "_source._id"
},
"tags" : {
"script" : "_source.tags"
}
},
"size" : 5
}
Now after I perform the search I need to build my domain objects from
the returned data. I am doing something like this
for ( Map.Entry<String, SearchHitField> entry :
hit.getFields().entrySet() ) {
String fieldName = entry.getKey();
if ( fieldName.equals("tags") ) {
//do something with tags
LOG.debug("TAG VALUE = " +
entry.getValue().getValue());
} else {
//do something
}
}
Now the problem is entry.getValue().getValue() returns an Object, and
I have no way of manipulating that data. If I do a toString() on the
object value, I get the toString() version as
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.