# Elasticsearch Embedded Index Exact Match Query Is Not Working

**URL:** <https://discuss.elastic.co/t/elasticsearch-embedded-index-exact-match-query-is-not-working/18190>\
**Category:** Elasticsearch\
**Created:** [June 18, 2014, 5:36pm UTC](https://discuss.elastic.co/t/elasticsearch-embedded-index-exact-match-query-is-not-working/18190 "2014-06-18T17:36:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![K\_Samanth\_Kumar\_Redd](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@K\_Samanth\_Kumar\_Redd](https://discuss.elastic.co/u/K_Samanth_Kumar_Redd)\
**Post date:** [June 18, 2014, 5:36pm UTC](https://discuss.elastic.co/t/elasticsearch-embedded-index-exact-match-query-is-not-working/18190/1 "2014-06-18T17:36:38Z")

</div>

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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/21fd3b58-9ecc-42a0-85d8-04d680f02c51%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![K\_Samanth\_Kumar\_Redd](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@K\_Samanth\_Kumar\_Redd](https://discuss.elastic.co/u/K_Samanth_Kumar_Redd)\
**Post date:** [June 19, 2014, 12:49pm UTC](https://discuss.elastic.co/t/elasticsearch-embedded-index-exact-match-query-is-not-working/18190/2 "2014-06-19T12:49:22Z")

</div>

It seems exact match query is not working on embedded index of elastic  
search.

Is this an issue with Elasticsearch?

Is there any one to help me on this?

Thanks,  
Samanth

On Wednesday, June 18, 2014 11:06:38 PM UTC+5:30, K.Samanth Kumar Reddy  
wrote:

> 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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/7248fa04-c2b3-4b80-926e-662c29e76dd5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7248fa04-c2b3-4b80-926e-662c29e76dd5%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:21am UTC](https://discuss.elastic.co/t/elasticsearch-embedded-index-exact-match-query-is-not-working/18190/3 "2017-07-06T01:21:10Z")

</div>


