By default, the source is returned. Use any of the source methods on the
GetResponse. If you want to get just a specific field, you can ask for it
in the get request (and then, _source will not be returned unless you ask
for it explicitly as well).
Thanks for the info.
I tried the following code:
"GetResponse response = client.prepareGet(index, type,
id).setFields("title").execute().actionGet();"
and it returned with the "title" object.
The "setFields" option is what did the trick.
Thanks again.
By default, the source is returned. Use any of the source methods on the
GetResponse. If you want to get just a specific field, you can ask for it
in the get request (and then, _source will not be returned unless you ask
for it explicitly as well).
what about when you want multiple fields. I tried a comma delimited list
and it assumed the entire string was the field name. I tried calling
setFields for each field and it only takes the last field. I tried setting
setField with a String[] but that too failed. Is there something I'm
missing here?
How are you indexing it? Is it a field with multiple values (an array in json)? If so, you will get an array back.
On Wednesday, February 22, 2012 at 8:02 PM, Wes Plunk wrote:
what about when you want multiple fields. I tried a comma delimited list and it assumed the entire string was the field name. I tried calling setFields for each field and it only takes the last field. I tried setting setField with a String but that too failed. Is there something I'm missing here?
The setFields method accepts multiple strings as parameters:
GetResponse response = client.prepareGet(index, type, id).setFields("title",
"name","postDate").execute().actionGet();
String title = (String)response.field("title").getValue();
String name = (String)response.field("name").getValue();
String postDate = (String)response.field("postDate").getValue();
El miércoles, 22 de febrero de 2012 19:02:29 UTC+1, Wes Plunk escribió:
what about when you want multiple fields. I tried a comma delimited list
and it assumed the entire string was the field name. I tried calling
setFields for each field and it only takes the last field. I tried setting
setField with a String but that too failed. Is there something I'm
missing here?
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.