Created
September 27, 2011 22:56
-
-
Save anonymous/1246499 to your computer and use it in GitHub Desktop.
.setFields("_source.obj") vs .setFields("obj"): The latter results in NullPointerException
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test | |
import scala.collection.JavaConversions._ | |
import org.elasticsearch.node.NodeBuilder._ | |
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest | |
import org.elasticsearch.client.Requests._ | |
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest | |
object Test_1 extends App { | |
val node = nodeBuilder().local(true).node | |
val client = node.client | |
val source = """{"message": "hi", "field": 123, "obj":{"abc": "123"}}""" | |
try { | |
client.admin.indices.create(new CreateIndexRequest("twitter")).actionGet() | |
} catch { | |
case e => println("Index already exists " + e); | |
} | |
client.admin.cluster.health(new ClusterHealthRequest("twitter").waitForYellowStatus).actionGet() | |
val indexResponse = client.prepareIndex("twitter", "tweet") | |
.setSource(source) | |
.setId("id1") | |
.execute() | |
.actionGet() | |
client.admin().indices().refresh(refreshRequest()).actionGet() | |
try { | |
val getResponse2 = client.prepareGet("twitter", "tweet", "id1") | |
.setFields("_source.obj") | |
.execute() | |
.actionGet() | |
println("Response " + ((getResponse2.field("_source.obj")).values())) | |
val getResponse1 = client.prepareGet("twitter", "tweet", "id1") | |
.setFields("obj") | |
.execute() | |
.actionGet() | |
println("Response " + ((getResponse1.field("obj")).values())) | |
node.close() | |
println("--- done ---") | |
} catch { | |
case e => println(e) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment