Hi,
I am using Lucene for last one year. I was successful in creating and
querying indexes using Lucene.
Now I am newbie to elasticsearch. As a beginner of elasticsearch, I have
created an embedded index using JAVA API.
And I tried to query the index for exact match, I am failed, I am getting
zero results.
Please find the sample code below:
- Am I creating embedded index in the right way?
- How to query exact match?
- Can you please suggest me any example for embedded index creating and
querying using java?
I have an urgent requirement, Can anybody please help me on this?
Thanks,
Samanth
//////////////////////////////////////////////////
/////// Indexing
//////////////////////////////////////////////////
// settings to initialize the node
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
settings.put("path.home", System.getProperty("user.home")+"/elasticSearch");
Node node =
NodeBuilder.nodeBuilder().settings(settings).clusterName("temp_cluster").node();
// Get the client
Client client = node.client();
String indexName = "index1";
String indexType = "type1";
String jsonString1 = " {"name":"elasticsearch"} ";
client.prepareIndex(indexName, indexType, "1")
.setSource(jsonString1).execute().actionGet();
String jsonString2 = " {"name":"search"} ";
client.prepareIndex(indexName, indexType, "2")
.setSource(jsonString2).execute().actionGet();
////////////////////////////////////////
// Searching
////////////////////////////////////////
QueryBuilder queryBuilder = QueryBuilders.termQuery("name",
"elasticsearch");
SearchRequestBuilder requestBuilder =
client.prepareSearch(indexName)
.setTypes(indexType)
.setQuery(queryBuilder.toString());
SearchResponse response1 = requestBuilder.execute().actionGet();
SearchHit[] results = response1.getHits().getHits();
System.out.println("Current Search Result Size: " + results.length);
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/21fd3b58-9ecc-42a0-85d8-04d680f02c51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.