# Bulk builder not working

**URL:** <https://discuss.elastic.co/t/bulk-builder-not-working/8058>\
**Category:** Elasticsearch\
**Created:** [June 12, 2012, 12:18pm UTC](https://discuss.elastic.co/t/bulk-builder-not-working/8058 "2012-06-12T12:18:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saurabh](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Saurabh](https://discuss.elastic.co/u/Saurabh)\
**Post date:** [June 12, 2012, 12:18pm UTC](https://discuss.elastic.co/t/bulk-builder-not-working/8058/1 "2012-06-12T12:18:26Z")

</div>

I am new to ElasticSearch. I tried the sample BulkRequestBuilder code to  
populate the index, but when i am retrieving the index by a query it gives  
0 hits.  
i am using the following code for indexing. Please help

```
public void createIndex() throws IOException {
try {
    BulkRequestBuilder bulkRequest = client.prepareBulk();

```

client.admin().indices().prepareCreate(indexName).execute().actionGet();

```
    IndexRequestBuilder req = client.prepareIndex("twitter", "tweet", 

```

"1")  
.setSource(jsonBuilder()  
.startObject()  
.field("user", "kimchy")  
.field("postDate", "12 June")  
.field("message", "trying out Elastic Search")  
.endObject()  
);  
bulkRequest.add(req);

```
    bulkRequest.add(client.prepareIndex("twitter", "tweet", "2")
            .setSource(jsonBuilder()
                        .startObject()
                            .field("user", "kimchy")
                            .field("postDate", "12 June")
                            .field("message", "another post")
                        .endObject()
                      )
            );
    
    BulkResponse bulkResponse = bulkRequest.execute().actionGet();
    System.out.println("Added documents");

    if (bulkResponse.hasFailures()) {
        System.out.println("Error");
    }
}
    
    
    
catch (IndexAlreadyExistsException e) {
    System.out.println("Index already exists");
}
}
```

---

<div class="post-metadata">

**Author:** ![Saurabh](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Saurabh](https://discuss.elastic.co/u/Saurabh)\
**Post date:** [June 12, 2012, 12:24pm UTC](https://discuss.elastic.co/t/bulk-builder-not-working/8058/2 "2012-06-12T12:24:01Z")

</div>

> the search code is:

```
public SearchHits search(String fieldName, String value) {
TermQueryBuilder query = new TermQueryBuilder(fieldName, value);
//System.out.println(query);
 return 

```

client.prepareSearch(indexName).setTypes("tweet").setExplain(true).setQuery(query).execute().actionGet().getHits();  
}

("user", "kimchy") are the passes parameters.

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [June 12, 2012, 5:03pm UTC](https://discuss.elastic.co/t/bulk-builder-not-working/8058/3 "2012-06-12T17:03:14Z")

</div>

Are you using the default mapping? Your are using a TermQuery, which  
should be used only on non-analyzed fields. That said, the term  
"kimchy" should be the same, analyzed or not. Is indexName = to  
"twitter"? Any errors in bulkResponse? Check  
bulkResponse.items().length and bulkResponse.hasFailures().

--  
Ivan

On Tue, Jun 12, 2012 at 5:24 AM, Saurabh [saurabh.k1510@gmail.com](mailto:saurabh.k1510@gmail.com) wrote:

> > the search code is:
> 
> ```
> public SearchHits search(String fieldName, String value) {
> TermQueryBuilder query = new TermQueryBuilder(fieldName, value);
> //System.out.println(query);
> return
> 
> ```
> 
> client.prepareSearch(indexName).setTypes("tweet").setExplain(true).setQuery(query).execute().actionGet().getHits();  
> }
> 
> ("user", "kimchy") are the passes parameters.

---

<div class="post-metadata">

**Author:** ![Saurabh](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Saurabh](https://discuss.elastic.co/u/Saurabh)\
**Post date:** [June 12, 2012, 5:21pm UTC](https://discuss.elastic.co/t/bulk-builder-not-working/8058/4 "2012-06-12T17:21:51Z")

</div>

Yes, the mapping is default and the indexName is "twitter". bulkResponse  
does not have any failures. Is there any way to check whether the documents  
are added in the index?

On Tue, Jun 12, 2012 at 10:33 PM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> Are you using the default mapping? Your are using a TermQuery, which  
> should be used only on non-analyzed fields. That said, the term  
> "kimchy" should be the same, analyzed or not. Is indexName = to  
> "twitter"? Any errors in bulkResponse? Check  
> bulkResponse.items().length and bulkResponse.hasFailures().
> 
> --  
> Ivan
> 
> On Tue, Jun 12, 2012 at 5:24 AM, Saurabh [saurabh.k1510@gmail.com](mailto:saurabh.k1510@gmail.com) wrote:
> 
> > > the search code is:
> > 
> > ```
> > public SearchHits search(String fieldName, String value) {
> > TermQueryBuilder query = new TermQueryBuilder(fieldName, value);
> > //System.out.println(query);
> > return
> > 
> > ```
> 
> client.prepareSearch(indexName).setTypes("tweet").setExplain(true).setQuery(query).execute().actionGet().getHits();
> 
> > ```
> > }
> > 
> > ```
> > 
> > ("user", "kimchy") are the passes parameters.

--  
Saurabh Kumar  
M.Sc (Mathematics) B.E (Computer Science)  
Birla Institute of Technology and Science-Pilani

---

<div class="post-metadata">

**Author:** ![Saurabh](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Saurabh](https://discuss.elastic.co/u/Saurabh)\
**Post date:** [June 13, 2012, 4:42am UTC](https://discuss.elastic.co/t/bulk-builder-not-working/8058/5 "2012-06-13T04:42:31Z")

</div>

After a bit of researching i got a small app that tells number of document  
in the ES index. I ran that application, and figured out that the documents  
are not getting added to the index. The search code looks fine to me. Any  
idea why the documents are not getting added using bulkRequestBuilder?

On Tue, Jun 12, 2012 at 10:51 PM, Saurabh Kumar [saurabh.k1510@gmail.com](mailto:saurabh.k1510@gmail.com)wrote:

> Yes, the mapping is default and the indexName is "twitter". bulkResponse  
> does not have any failures. Is there any way to check whether the documents  
> are added in the index?
> 
> On Tue, Jun 12, 2012 at 10:33 PM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:
> 
> > Are you using the default mapping? Your are using a TermQuery, which  
> > should be used only on non-analyzed fields. That said, the term  
> > "kimchy" should be the same, analyzed or not. Is indexName = to  
> > "twitter"? Any errors in bulkResponse? Check  
> > bulkResponse.items().length and bulkResponse.hasFailures().
> > 
> > --  
> > Ivan
> > 
> > On Tue, Jun 12, 2012 at 5:24 AM, Saurabh [saurabh.k1510@gmail.com](mailto:saurabh.k1510@gmail.com) wrote:
> > 
> > > > the search code is:
> > > 
> > > ```
> > > public SearchHits search(String fieldName, String value) {
> > > TermQueryBuilder query = new TermQueryBuilder(fieldName, value);
> > > //System.out.println(query);
> > > return
> > > 
> > > ```
> > 
> > client.prepareSearch(indexName).setTypes("tweet").setExplain(true).setQuery(query).execute().actionGet().getHits();
> > 
> > > ```
> > > }
> > > 
> > > ```
> > > 
> > > ("user", "kimchy") are the passes parameters.
> 
> --  
> Saurabh Kumar  
> M.Sc (Mathematics) B.E (Computer Science)  
> Birla Institute of Technology and Science-Pilani

--  
Saurabh Kumar  
M.Sc (Mathematics) B.E (Computer Science)  
Birla Institute of Technology and Science-Pilani

---

<div class="post-metadata">

**Author:** ![Saurabh](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Saurabh](https://discuss.elastic.co/u/Saurabh)\
**Post date:** [June 13, 2012, 5:14am UTC](https://discuss.elastic.co/t/bulk-builder-not-working/8058/6 "2012-06-13T05:14:22Z")

</div>

I got the answer. I was doing the search wrong, I gave the type as "tweet"  
but while searching i was only giving fieldName as "user" , however it  
should have been "tweet.user" . Its giving 2 hits now. Thanks for the reply  
anyways.

---

<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, 3:24am UTC](https://discuss.elastic.co/t/bulk-builder-not-working/8058/7 "2017-07-06T03:24:41Z")

</div>


