# Remove white spaces when using XContentBuilder

**URL:** <https://discuss.elastic.co/t/remove-white-spaces-when-using-xcontentbuilder/10790>\
**Category:** Elasticsearch\
**Created:** [February 19, 2013, 5:19am UTC](https://discuss.elastic.co/t/remove-white-spaces-when-using-xcontentbuilder/10790 "2013-02-19T05:19:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mukesh](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mukesh](https://discuss.elastic.co/u/mukesh)\
**Post date:** [February 19, 2013, 5:19am UTC](https://discuss.elastic.co/t/remove-white-spaces-when-using-xcontentbuilder/10790/1 "2013-02-19T05:19:51Z")

</div>

Hello sir  
I want to remove whitespaces and using trim()

```
             XContentBuilder builder = XContentFactory.jsonBuilder()
                    .startObject();

```

builder.field("From", emails.get(i).from.trim());

but find :Exception in thread "main" java.lang.NullPointerException  
and also Node not created

============================================================

On Mon, Feb 18, 2013 at 4:36 PM, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) wrote:

> Thanks sir for support
> 
> ====================================================================
> 
> On Mon, Feb 18, 2013 at 1:52 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > Prefix filter is not analyzed. See  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/prefix-filter.html)
> > 
> > So, if you want to use it here, use it with a Capital N
> > 
> > --  
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > 
> > Le 18 févr. 2013 à 09:20, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit :
> > 
> > yes i have CurrentLocation:Navi Mumbai  
> > ok i have change CurrentLocation:delhi but  
> > i think when we using prefixFilter than match with "null" if  
> > no any match found and should return result so My question still same why  
> > Filter not working when comments out than find result
> > 
> > # { "took" : 31, "timed\_out" : false, "\_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 0, "max\_score" : null, "hits" : } } so please suggest me how to search on the basis of skills and location with java api?
> > 
> > On Mon, Feb 18, 2013 at 12:24 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> > 
> > > Do you have a document with CurrentLocation=n ?
> > > 
> > > Hard to say something else as we don't know your mapping either your  
> > > docs.
> > > 
> > > --  
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > Le 18 févr. 2013 à 07:00, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit :
> > > 
> > > I have already facing same problem
> > > 
> > > Settings settings = ImmutableSettings.settingsBuilder().put("  
> > > cluster.name", "elasticsearch").build();  
> > > Client client = new  
> > > TransportClient(settings).addTransportAddress(new  
> > > InetSocketTransportAddress("192.168.1.16", 9300));
> > > 
> > > client.admin().indices().prepareRefresh("resume\_index").execute().actionGet();  
> > > FilterBuilders.andFilter(  
> > > FilterBuilders.prefixFilter("keyskil", "asp"),  
> > > FilterBuilders.prefixFilter("CurrentLocation", "delhi")  
> > > );  
> > > AndFilterBuilder queryFilters = FilterBuilders.andFilter();  
> > > queryFilters.add(FilterBuilders.prefixFilter("keyskil",  
> > > "asp"));
> > > 
> > > queryFilters.add(FilterBuilders.prefixFilter("CurrentLocation", "n"));  
> > > FilterBuilder aggFilter =  
> > > FilterBuilders.andFilter(queryFilters);  
> > > SearchResponse response =  
> > > client.prepareSearch("resume\_index")
> > > 
> > > .setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
> > > //.setFilter(aggFilter)
> > > 
> > > //.setQuery(QueryBuilders.termQuery("KeySkills", "red"))
> > > 
> > > //.setQuery(QueryBuilders.prefixQuery("CurrentLocation","n"))  
> > > .setFrom(0)  
> > > .setSize(2)  
> > > .setExplain(true)  
> > > .execute()  
> > > .actionGet();
> > > 
> > > ```
> > > System.out.println(response.toString());
> > > String s=response.toString();
> > > 
> > > ```
> > > 
> > > find result:
> > > 
> > > {  
> > > "took" : 0,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 5,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 261,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_shard" : 0,  
> > > "\_node" : "Gik4Z040QSSzsNRlS9sVew",  
> > > "\_index" : "resume\_index",  
> > > "_type" : "emls_",  
> > > "\_id" : "\<  
> > > [CAFV6cM-pUaUTLFv-uDvTXHvYDHOV61vyQL5WdxAfiGLmBYkcLail.com](http://CAFV6cM-pUaUTLFv-uDvTXHvYDHOV61vyQL5WdxAfiGLmBYkcLail.com)[http://cafv6cm-puautlfv-udvtxhvydhov61vyql5wdxafiglmbykclail.com/](http://cafv6cm-puautlfv-udvtxhvydhov61vyql5wdxafiglmbykclail.com/)
> > > 
> > > > ",  
> > > > "\_score" : 1.0, "\_source" : {"From":"ajay.singh@com","Subject":"Fwd:  
> > > > check file parser","Path":"E:\emls\output\ajacom.lalituttam\_129.doc  
> > > > ","ResumeHeadline":"[asp.net](http://asp.net) developerhaving 2 year and 5 months  
> > > > experience ","KeySkills":"[ASP.Net](http://ASP.Net) [http://asp.net/](http://asp.net/) & C#.NetWith  
> > > > SQLServer 2005 ","Name":"saris kumar gupta ","TotalExperience":"2 Years, 1  
> > > > Months ","CTC":"Rs1.45 lacs ","CurrentEmployer":"IAP Company Limited  
> > > > ","CurrentDesignation":"SoftwareProgrammer  
> > > > ","LastEmployer":null,"LastDesignation":null,"CurrentLocation":null,"PreferredLocation":null,"Education":"B.A,  
> > > > MCA ","Mobile":"7388852980 ","Landline":"91-- ","Recommendations":"Not  
> > > > Mentioned ","Lastmodifiedon":"14-Mar-2012 "},  
> > > > "\_explanation" : {  
> > > > "value" : 1.0,  
> > > > "description" : "ConstantScore(NotDeleted(_:_)), product of:",  
> > > > "details" : [ {  
> > > > "value" : 1.0,  
> > > > "description" : "boost"  
> > > > }, {  
> > > > "value" : 1.0,  
> > > > "description" : "queryNorm"  
> > > > } ]  
> > > > }  
> > > > }, {............................
> > > 
> > > but when //.setFilter(aggFilter) comments out then find result
> > > 
> > > {  
> > > "took" : 16,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 5,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 0,  
> > > "max\_score" : null,  
> > > "hits" :   
> > > }  
> > > } please let me know whats the error? I want search on basis of multiple  
> > > filed..
> > > 
> > > ============================================================================
> > > 
> > > On Wednesday, February 1, 2012 3:10:11 PM UTC+5:30, kimchy wrote:
> > > 
> > > > Its probably because the title is analyzed, so its broken down into  
> > > > (modified) terms, for example, "Person template" will be broken down into  
> > > > two tokens, "person" and "template". When you use term filter, it only  
> > > > works on actual tokens. You can have the title not analyzed in the mapping  
> > > > (or use a multi field mapping that has it both as analyzed and  
> > > > not\_analyzed) and then filter on the not analyzed version of it.
> > > > 
> > > > On Wednesday, February 1, 2012 at 2:35 AM, Ariel Mendoza wrote:
> > > > 
> > > > Hi Shay,
> > > > 
> > > > I am using AndFilterBuilder. Here are the results when setFilter(fb)  
> > > > is commented-out.
> > > > 
> > > > Search 'Person': took 68ms, shards 1:0  
> > > > hit: 0.220823 test\_db1/template/CrmPerson(\*\*ver 1)  
> > > > hit: 0.220823 test\_db1/template/CrmCompany(\*\*ver 1)  
> > > > hit: 0.126185 test\_db1/Person/W2.7(ver 1)  
> > > > hit: 0.126185 test\_db1/Person/W2.8(ver 1)  
> > > > hit: 0.126185 test\_db1/Person/W2.9(ver 1)  
> > > > hit: 0.126185 test\_db1/Person/W2.10(ver 1)  
> > > > hit: 0.126185 test\_db1/Person/W2.11(ver 1)  
> > > > hit: 0.126185 test\_db1/Person/W2.12(ver 1)  
> > > > hit: 0.126185 test\_db1/Person/W2.13(ver 1)  
> > > > hit: 0.126185 test\_db1/Person/W2.14(ver 1)
> > > > 
> > > > {"title":"Person template","desc":"Person template","path":"/  
> > > > test\_db1/template/CrmPerson"\*\*,"version":1},{"title":"Person  
> > > > template","desc":"Person template","path":"/test\_db1/\*\*template/  
> > > > CrmCompany","version":1},{"\*\*title":"Steven Boutte","desc":"Contacts  
> > > > person document containing details of Steven Boutte","path":"/  
> > > > test\_db1/Person/W2.7","\*\*version":1},{"title":"Joe  
> > > > Hunter","desc":"Contacts person document containing details of Joe  
> > > > Hunter","path":"/test\_db1/\*\*Person/W2.8","version":1},  
> > > > {"title":"Joseph Wells","desc":"Contacts person document containing  
> > > > details of Joseph Wells","path":"/test\_db1/**Person/W2.9","version":  
> > > > 1},{"title":"Albert Brown","desc":"Contacts person document containing  
> > > > details of Albert Brown","path":"/test\_db1/**  
> > > > Person/W2.10","version":  
> > > > 1},{"title":"Mike Rivera","desc":"Contacts person document containing  
> > > > details of Mike Rivera","path":"/test\_db1/\*\*Person/W2.11","version":  
> > > > 1},{"title":"Sandra Hohl","desc":"Contacts person document containing  
> > > > details of Sandra Hohl","path":"/test\_db1/\*\*Person/W2.12","version":  
> > > > 1},{"title":"Curt Adamski","desc":"Contacts person document c  
> > > > ontaining details of Curt Adamski","path":"/test\_db1/\*\*Person/  
> > > > W2.13","version":1},{"title":"\*\*Darlene Quandt","desc":"Contacts person  
> > > > document containing details of Darlene Quandt","path":"/test\_db1/  
> > > > Person/W2.14","version":1}
> > > > 
> > > > From the results above, I would like to filter those with title =  
> > > > "Person template" or version = 1. But, I fail to do so provided the  
> > > > codes below:
> > > > 
> > > > QueryBuilder qb =  
> > > > QueryBuilders.queryString("\*\*Person");
> > > > 
> > > > AndFilterBuilder myFilters =  
> > > > FilterBuilders.andFilter();  
> > > > //  
> > > > myFilters.add(FilterBuilders.\*\*termFilter("version", "1"));  
> > > > myFilters.add(FilterBuilders.\*\*termFilter("title", "Person  
> > > > template"));
> > > > 
> > > > // QueryBuilder qb =  
> > > > QueryBuilders.filteredQuery(\*\*QueryBuilders.queryString(\*\*query),  
> > > > myFilters);
> > > > 
> > > > // QueryBuilder qb =  
> > > > QueryBuilders.filteredQuery(\*\*QueryBuilders.queryString(\*\*query),  
> > > > // FilterBuilders.queryFilter( ... ));
> > > > 
> > > > searchResponse = client.prepareSearch(dbName)  
> > > > .setSearchType(SearchType.\*\*QUERY\_THEN\_FETCH)  
> > > > .setQuery(qb)  
> > > > .setFilter(myFilters)  
> > > > .setVersion(true)  
> > > > .setFrom(start)  
> > > > .setSize(size)  
> > > > // .setExplain(true) // Explain hit score  
> > > > // .setNoFields() // Do not return  
> > > > stored fields  
> > > > .addField("document.title")  
> > > > .addField("document.desc")  
> > > > .execute()  
> > > > .actionGet();
> > > > 
> > > > Thanks,  
> > > > Ariel
> > > > 
> > > > On Feb 1, 1:42 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > > 
> > > > Really hard to help without knowing what filter you use, the data you  
> > > > index, and how its mapped...
> > > > 
> > > > On Tuesday, January 31, 2012 at 11:22 AM, Ariel Mendoza wrote:
> > > > 
> > > > I am using Java API for text search. Refer to the codes below, when I  
> > > > execute it, no record is retrieve though the Filter parameters of  
> > > > field and value pair I've set are correct, but when I comment-out or  
> > > > remove the .setFilter(fb), the search works fine. Please let me know  
> > > > if I'm doing this wrong or are there other approach to achieve my  
> > > > goal?
> > > > 
> > > > searchResponse = client.prepareSearch(dbName)  
> > > > .setSearchType(SearchType.\*\*QUERY\_THEN\_FETCH)  
> > > > .setQuery(qb)  
> > > > .setFilter(fb)  
> > > > .setVersion(true)  
> > > > .setFrom(start)  
> > > > .setSize(size)  
> > > > // .setExplain(true) // Explain hit score  
> > > > // .setNoFields() // Do not return  
> > > > stored fields  
> > > > .addField("document.title")  
> > > > .addField("document.desc")  
> > > > .execute()  
> > > > .actionGet();
> > > 
> > > --  
> > > 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).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > 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).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> > Laitkor.infosolution pvt ltd
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> Laitkor.infosolution pvt ltd

--  
[mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
Laitkor.infosolution pvt ltd

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 19, 2013, 6:43am UTC](https://discuss.elastic.co/t/remove-white-spaces-when-using-xcontentbuilder/10790/2 "2013-02-19T06:43:47Z")

</div>

The NPE is probably in your code:  
emails.get(i).from.trim()

This is not relative to Elasticsearch.

That said, why do you think you need to remove white spaces?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 19 févr. 2013 à 06:19, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit :

Hello sir  
I want to remove whitespaces and using trim()

```
             XContentBuilder builder = XContentFactory.jsonBuilder()
                    .startObject();

```

builder.field("From", emails.get(i).from.trim());

but find :Exception in thread "main" java.lang.NullPointerException  
and also Node not created

============================================================

On Mon, Feb 18, 2013 at 4:36 PM, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) wrote:

> Thanks sir for support
> 
> ====================================================================
> 
> On Mon, Feb 18, 2013 at 1:52 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > Prefix filter is not analyzed. See [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/prefix-filter.html)
> > 
> > So, if you want to use it here, use it with a Capital N
> > 
> > --  
> > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > @dadoonet | @elasticsearchfr | @scrutmydocs
> > 
> > Le 18 févr. 2013 à 09:20, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit :
> > 
> > > yes i have CurrentLocation:Navi Mumbai  
> > > ok i have change CurrentLocation:delhi but  
> > > i think when we using prefixFilter than match with "null" if no any match found and should return result so My question still same why Filter not working when comments out than find result
> > > 
> > > # { "took" : 31, "timed\_out" : false, "\_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 0, "max\_score" : null, "hits" : } } so please suggest me how to search on the basis of skills and location with java api?
> > > 
> > > On Mon, Feb 18, 2013 at 12:24 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> > > 
> > > > Do you have a document with CurrentLocation=n ?
> > > > 
> > > > Hard to say something else as we don't know your mapping either your docs.
> > > > 
> > > > --  
> > > > David 😉  
> > > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > > 
> > > > Le 18 févr. 2013 à 07:00, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit :
> > > > 
> > > > I have already facing same problem
> > > > 
> > > > Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "elasticsearch").build();  
> > > > Client client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("192.168.1.16", 9300));  
> > > > client.admin().indices().prepareRefresh("resume\_index").execute().actionGet();  
> > > > FilterBuilders.andFilter(  
> > > > FilterBuilders.prefixFilter("keyskil", "asp"),  
> > > > FilterBuilders.prefixFilter("CurrentLocation", "delhi")  
> > > > );  
> > > > AndFilterBuilder queryFilters = FilterBuilders.andFilter();  
> > > > queryFilters.add(FilterBuilders.prefixFilter("keyskil", "asp"));  
> > > > queryFilters.add(FilterBuilders.prefixFilter("CurrentLocation", "n"));  
> > > > FilterBuilder aggFilter = FilterBuilders.andFilter(queryFilters);  
> > > > SearchResponse response = client.prepareSearch("resume\_index")  
> > > > .setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
> > > > //.setFilter(aggFilter)  
> > > > //.setQuery(QueryBuilders.termQuery("KeySkills", "red"))  
> > > > //.setQuery(QueryBuilders.prefixQuery("CurrentLocation","n"))  
> > > > .setFrom(0)  
> > > > .setSize(2)  
> > > > .setExplain(true)  
> > > > .execute()  
> > > > .actionGet();
> > > > 
> > > > ```
> > > > System.out.println(response.toString());
> > > > String s=response.toString();
> > > > 
> > > > ```
> > > > 
> > > > find result:
> > > > 
> > > > {  
> > > > "took" : 0,  
> > > > "timed\_out" : false,  
> > > > "\_shards" : {  
> > > > "total" : 5,  
> > > > "successful" : 5,  
> > > > "failed" : 0  
> > > > },  
> > > > "hits" : {  
> > > > "total" : 261,  
> > > > "max\_score" : 1.0,  
> > > > "hits" : [ {  
> > > > "\_shard" : 0,  
> > > > "\_node" : "Gik4Z040QSSzsNRlS9sVew",  
> > > > "\_index" : "resume\_index",  
> > > > "_type" : "emls_",  
> > > > "\_id" : "\<[CAFV6cM-pUaUTLFv-uDvTXHvYDHOV61vyQL5WdxAfiGLmBYkcLail.com](http://CAFV6cM-pUaUTLFv-uDvTXHvYDHOV61vyQL5WdxAfiGLmBYkcLail.com)\>",  
> > > > "\_score" : 1.0, "\_source" : {"From":"ajay.singh@com","Subject":"Fwd: check file parser","Path":"E:\emls\output\ajacom.lalituttam\_129.doc","ResumeHeadline":"[asp.net](http://asp.net) developerhaving 2 year and 5 months experience ","KeySkills":"[ASP.Net](http://ASP.Net) & C#.NetWith SQLServer 2005 ","Name":"saris kumar gupta ","TotalExperience":"2 Years, 1 Months ","CTC":"Rs1.45 lacs ","CurrentEmployer":"IAP Company Limited ","CurrentDesignation":"SoftwareProgrammer ","LastEmployer":null,"LastDesignation":null,"CurrentLocation":null,"PreferredLocation":null,"Education":"B.A, MCA ","Mobile":"7388852980 ","Landline":"91-- ","Recommendations":"Not Mentioned ","Lastmodifiedon":"14-Mar-2012 "},  
> > > > "\_explanation" : {  
> > > > "value" : 1.0,  
> > > > "description" : "ConstantScore(NotDeleted(_:_)), product of:",  
> > > > "details" : [ {  
> > > > "value" : 1.0,  
> > > > "description" : "boost"  
> > > > }, {  
> > > > "value" : 1.0,  
> > > > "description" : "queryNorm"  
> > > > } ]  
> > > > }  
> > > > }, {............................
> > > > 
> > > > but when //.setFilter(aggFilter) comments out then find result
> > > > 
> > > > # { "took" : 16, "timed\_out" : false, "\_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 0, "max\_score" : null, "hits" : } } please let me know whats the error? I want search on basis of multiple filed..
> > > > 
> > > > On Wednesday, February 1, 2012 3:10:11 PM UTC+5:30, kimchy wrote:
> > > > 
> > > > > Its probably because the title is analyzed, so its broken down into (modified) terms, for example, "Person template" will be broken down into two tokens, "person" and "template". When you use term filter, it only works on actual tokens. You can have the title not analyzed in the mapping (or use a multi field mapping that has it both as analyzed and not\_analyzed) and then filter on the not analyzed version of it.  
> > > > > On Wednesday, February 1, 2012 at 2:35 AM, Ariel Mendoza wrote:
> > > > > 
> > > > > > Hi Shay,
> > > > > > 
> > > > > > I am using AndFilterBuilder. Here are the results when setFilter(fb)  
> > > > > > is commented-out.
> > > > > > 
> > > > > > Search 'Person': took 68ms, shards 1:0  
> > > > > > hit: 0.220823 test\_db1/template/CrmPerson(ver 1)  
> > > > > > hit: 0.220823 test\_db1/template/CrmCompany(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.7(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.8(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.9(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.10(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.11(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.12(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.13(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.14(ver 1)
> > > > > > 
> > > > > > {"title":"Person template","desc":"Person template","path":"/  
> > > > > > test\_db1/template/CrmPerson","version":1},{"title":"Person  
> > > > > > template","desc":"Person template","path":"/test\_db1/template/  
> > > > > > CrmCompany","version":1},{"title":"Steven Boutte","desc":"Contacts  
> > > > > > person document containing details of Steven Boutte","path":"/  
> > > > > > test\_db1/Person/W2.7","version":1},{"title":"Joe  
> > > > > > Hunter","desc":"Contacts person document containing details of Joe  
> > > > > > Hunter","path":"/test\_db1/Person/W2.8","version":1},  
> > > > > > {"title":"Joseph Wells","desc":"Contacts person document containing  
> > > > > > details of Joseph Wells","path":"/test\_db1/Person/W2.9","version":  
> > > > > > 1},{"title":"Albert Brown","desc":"Contacts person document containing  
> > > > > > details of Albert Brown","path":"/test\_db1/Person/W2.10","version":  
> > > > > > 1},{"title":"Mike Rivera","desc":"Contacts person document containing  
> > > > > > details of Mike Rivera","path":"/test\_db1/Person/W2.11","version":  
> > > > > > 1},{"title":"Sandra Hohl","desc":"Contacts person document containing  
> > > > > > details of Sandra Hohl","path":"/test\_db1/Person/W2.12","version":  
> > > > > > 1},{"title":"Curt Adamski","desc":"Contacts person document c  
> > > > > > ontaining details of Curt Adamski","path":"/test\_db1/Person/  
> > > > > > W2.13","version":1},{"title":"Darlene Quandt","desc":"Contacts person  
> > > > > > document containing details of Darlene Quandt","path":"/test\_db1/  
> > > > > > Person/W2.14","version":1}
> > > > > > 
> > > > > > From the results above, I would like to filter those with title =  
> > > > > > "Person template" or version = 1. But, I fail to do so provided the  
> > > > > > codes below:
> > > > > > 
> > > > > > QueryBuilder qb =  
> > > > > > QueryBuilders.queryString("Person");
> > > > > > 
> > > > > > AndFilterBuilder myFilters =  
> > > > > > FilterBuilders.andFilter();  
> > > > > > //  
> > > > > > myFilters.add(FilterBuilders.termFilter("version", "1"));  
> > > > > > myFilters.add(FilterBuilders.termFilter("title", "Person template"));
> > > > > > 
> > > > > > // QueryBuilder qb =  
> > > > > > QueryBuilders.filteredQuery(QueryBuilders.queryString(query),  
> > > > > > myFilters);
> > > > > > 
> > > > > > // QueryBuilder qb =  
> > > > > > QueryBuilders.filteredQuery(QueryBuilders.queryString(query),  
> > > > > > // FilterBuilders.queryFilter( ... ));
> > > > > > 
> > > > > > searchResponse = client.prepareSearch(dbName)  
> > > > > > .setSearchType(SearchType.QUERY\_THEN\_FETCH)  
> > > > > > .setQuery(qb)  
> > > > > > .setFilter(myFilters)  
> > > > > > .setVersion(true)  
> > > > > > .setFrom(start)  
> > > > > > .setSize(size)  
> > > > > > // .setExplain(true) // Explain hit score  
> > > > > > // .setNoFields() // Do not return  
> > > > > > stored fields  
> > > > > > .addField("document.title")  
> > > > > > .addField("document.desc")  
> > > > > > .execute()  
> > > > > > .actionGet();
> > > > > > 
> > > > > > Thanks,  
> > > > > > Ariel
> > > > > > 
> > > > > > On Feb 1, 1:42 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > > > > 
> > > > > > > Really hard to help without knowing what filter you use, the data you index, and how its mapped...
> > > > > > > 
> > > > > > > On Tuesday, January 31, 2012 at 11:22 AM, Ariel Mendoza wrote:
> > > > > > > 
> > > > > > > > I am using Java API for text search. Refer to the codes below, when I  
> > > > > > > > execute it, no record is retrieve though the Filter parameters of  
> > > > > > > > field and value pair I've set are correct, but when I comment-out or  
> > > > > > > > remove the .setFilter(fb), the search works fine. Please let me know  
> > > > > > > > if I'm doing this wrong or are there other approach to achieve my  
> > > > > > > > goal?
> > > > > > > 
> > > > > > > > searchResponse = client.prepareSearch(dbName)  
> > > > > > > > .setSearchType(SearchType.QUERY\_THEN\_FETCH)  
> > > > > > > > .setQuery(qb)  
> > > > > > > > .setFilter(fb)  
> > > > > > > > .setVersion(true)  
> > > > > > > > .setFrom(start)  
> > > > > > > > .setSize(size)  
> > > > > > > > // .setExplain(true) // Explain hit score  
> > > > > > > > // .setNoFields() // Do not return  
> > > > > > > > stored fields  
> > > > > > > > .addField("document.title")  
> > > > > > > > .addField("document.desc")  
> > > > > > > > .execute()  
> > > > > > > > .actionGet();
> > > > 
> > > > --  
> > > > 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).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > 
> > > > --  
> > > > 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).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> > > Laitkor.infosolution pvt ltd
> > > 
> > > --  
> > > 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).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> Laitkor.infosolution pvt ltd

## -- [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) Laitkor.infosolution pvt ltd

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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mukesh](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mukesh](https://discuss.elastic.co/u/mukesh)\
**Post date:** [February 19, 2013, 8:00am UTC](https://discuss.elastic.co/t/remove-white-spaces-when-using-xcontentbuilder/10790/3 "2013-02-19T08:00:02Z")

</div>

This is my json

{  
.....  
"Education":" BCA","CurrentDesignation":" BCA",  
"LastEmployer":" Ait",  
"LastDesignation":" Developer",  
"CurrentLocation":" Delhi",  
"PreferredLocation":"Pune",  
"Mobile": 88888...,  
"Landline":" NotMentioned",  
"Recommendations":" Not Mentioned",  
"Lastmodifiedon":"11-Feb-2013"}}]}}

and when i search with  
AndFilterBuilder queryFilters = FilterBuilders.andFilter();  
queryFilters.add(FilterBuilders.prefixFilter("Education", "B"));

It will not give any Hits...but get Hits results only where value have no  
any whitespaces and its value in Lowercase

=================================================================

On Tue, Feb 19, 2013 at 12:13 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> The NPE is probably in your code:  
> emails.get(i).from.trim()
> 
> This is not relative to Elasticsearch.
> 
> That said, why do you think you need to remove white spaces?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 19 févr. 2013 à 06:19, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit :
> 
> Hello sir  
> I want to remove whitespaces and using trim()
> 
> ```
> XContentBuilder builder = XContentFactory.jsonBuilder()
> .startObject();
> 
> ```
> 
> builder.field("From", emails.get(i).from.trim());
> 
> but find :Exception in thread "main" java.lang.NullPointerException  
> and also Node not created
> 
> ============================================================
> 
> On Mon, Feb 18, 2013 at 4:36 PM, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)wrote:
> 
> > Thanks sir for support
> > 
> > ====================================================================
> > 
> > On Mon, Feb 18, 2013 at 1:52 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> > 
> > > Prefix filter is not analyzed. See  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/prefix-filter.html)
> > > 
> > > So, if you want to use it here, use it with a Capital N
> > > 
> > > --  
> > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > > 
> > > Le 18 févr. 2013 à 09:20, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit :
> > > 
> > > yes i have CurrentLocation:Navi Mumbai  
> > > ok i have change CurrentLocation:delhi but  
> > > i think when we using prefixFilter than match with "null" if  
> > > no any match found and should return result so My question still same why  
> > > Filter not working when comments out than find result
> > > 
> > > # { "took" : 31, "timed\_out" : false, "\_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 0, "max\_score" : null, "hits" : } } so please suggest me how to search on the basis of skills and location with java api?
> > > 
> > > On Mon, Feb 18, 2013 at 12:24 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> > > 
> > > > Do you have a document with CurrentLocation=n ?
> > > > 
> > > > Hard to say something else as we don't know your mapping either your  
> > > > docs.
> > > > 
> > > > --  
> > > > David 😉  
> > > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > > 
> > > > Le 18 févr. 2013 à 07:00, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a  
> > > > écrit :
> > > > 
> > > > I have already facing same problem
> > > > 
> > > > Settings settings = ImmutableSettings.settingsBuilder().put("  
> > > > cluster.name", "elasticsearch").build();  
> > > > Client client = new  
> > > > TransportClient(settings).addTransportAddress(new  
> > > > InetSocketTransportAddress("192.168.1.16", 9300));
> > > > 
> > > > client.admin().indices().prepareRefresh("resume\_index").execute().actionGet();  
> > > > FilterBuilders.andFilter(  
> > > > FilterBuilders.prefixFilter("keyskil", "asp"),  
> > > > FilterBuilders.prefixFilter("CurrentLocation", "delhi")  
> > > > );  
> > > > AndFilterBuilder queryFilters = FilterBuilders.andFilter();  
> > > > queryFilters.add(FilterBuilders.prefixFilter("keyskil",  
> > > > "asp"));
> > > > 
> > > > queryFilters.add(FilterBuilders.prefixFilter("CurrentLocation", "n"));  
> > > > FilterBuilder aggFilter =  
> > > > FilterBuilders.andFilter(queryFilters);  
> > > > SearchResponse response =  
> > > > client.prepareSearch("resume\_index")
> > > > 
> > > > .setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
> > > > //.setFilter(aggFilter)
> > > > 
> > > > //.setQuery(QueryBuilders.termQuery("KeySkills", "red"))
> > > > 
> > > > //.setQuery(QueryBuilders.prefixQuery("CurrentLocation","n"))  
> > > > .setFrom(0)  
> > > > .setSize(2)  
> > > > .setExplain(true)  
> > > > .execute()  
> > > > .actionGet();
> > > > 
> > > > ```
> > > > System.out.println(response.toString());
> > > > String s=response.toString();
> > > > 
> > > > ```
> > > > 
> > > > find result:
> > > > 
> > > > {  
> > > > "took" : 0,  
> > > > "timed\_out" : false,  
> > > > "\_shards" : {  
> > > > "total" : 5,  
> > > > "successful" : 5,  
> > > > "failed" : 0  
> > > > },  
> > > > "hits" : {  
> > > > "total" : 261,  
> > > > "max\_score" : 1.0,  
> > > > "hits" : [ {  
> > > > "\_shard" : 0,  
> > > > "\_node" : "Gik4Z040QSSzsNRlS9sVew",  
> > > > "\_index" : "resume\_index",  
> > > > "_type" : "emls_",  
> > > > "\_id" : "\<  
> > > > [CAFV6cM-pUaUTLFv-uDvTXHvYDHOV61vyQL5WdxAfiGLmBYkcLail.com](http://CAFV6cM-pUaUTLFv-uDvTXHvYDHOV61vyQL5WdxAfiGLmBYkcLail.com)[http://cafv6cm-puautlfv-udvtxhvydhov61vyql5wdxafiglmbykclail.com/](http://cafv6cm-puautlfv-udvtxhvydhov61vyql5wdxafiglmbykclail.com/)
> > > > 
> > > > > ",  
> > > > > "\_score" : 1.0, "\_source" : {"From":"ajay.singh@com","Subject":"Fwd:  
> > > > > check file parser","Path":"E:\emls\output\ajacom.lalituttam\_129.doc  
> > > > > ","ResumeHeadline":"[asp.net](http://asp.net) developerhaving 2 year and 5 months  
> > > > > experience ","KeySkills":"[ASP.Net](http://ASP.Net) [http://asp.net/](http://asp.net/) & C#.NetWith  
> > > > > SQLServer 2005 ","Name":"saris kumar gupta ","TotalExperience":"2 Years, 1  
> > > > > Months ","CTC":"Rs1.45 lacs ","CurrentEmployer":"IAP Company Limited  
> > > > > ","CurrentDesignation":"SoftwareProgrammer  
> > > > > ","LastEmployer":null,"LastDesignation":null,"CurrentLocation":null,"PreferredLocation":null,"Education":"B.A,  
> > > > > MCA ","Mobile":"7388852980 ","Landline":"91-- ","Recommendations":"Not  
> > > > > Mentioned ","Lastmodifiedon":"14-Mar-2012 "},  
> > > > > "\_explanation" : {  
> > > > > "value" : 1.0,  
> > > > > "description" : "ConstantScore(NotDeleted(_:_)), product of:",  
> > > > > "details" : [ {  
> > > > > "value" : 1.0,  
> > > > > "description" : "boost"  
> > > > > }, {  
> > > > > "value" : 1.0,  
> > > > > "description" : "queryNorm"  
> > > > > } ]  
> > > > > }  
> > > > > }, {............................
> > > > 
> > > > but when //.setFilter(aggFilter) comments out then find result
> > > > 
> > > > {  
> > > > "took" : 16,  
> > > > "timed\_out" : false,  
> > > > "\_shards" : {  
> > > > "total" : 5,  
> > > > "successful" : 5,  
> > > > "failed" : 0  
> > > > },  
> > > > "hits" : {  
> > > > "total" : 0,  
> > > > "max\_score" : null,  
> > > > "hits" :   
> > > > }  
> > > > } please let me know whats the error? I want search on basis of  
> > > > multiple filed..
> > > > 
> > > > ============================================================================
> > > > 
> > > > On Wednesday, February 1, 2012 3:10:11 PM UTC+5:30, kimchy wrote:
> > > > 
> > > > > Its probably because the title is analyzed, so its broken down into  
> > > > > (modified) terms, for example, "Person template" will be broken down into  
> > > > > two tokens, "person" and "template". When you use term filter, it only  
> > > > > works on actual tokens. You can have the title not analyzed in the mapping  
> > > > > (or use a multi field mapping that has it both as analyzed and  
> > > > > not\_analyzed) and then filter on the not analyzed version of it.
> > > > > 
> > > > > On Wednesday, February 1, 2012 at 2:35 AM, Ariel Mendoza wrote:
> > > > > 
> > > > > Hi Shay,
> > > > > 
> > > > > I am using AndFilterBuilder. Here are the results when setFilter(fb)  
> > > > > is commented-out.
> > > > > 
> > > > > Search 'Person': took 68ms, shards 1:0  
> > > > > hit: 0.220823 test\_db1/template/CrmPerson(\*\*ver 1)  
> > > > > hit: 0.220823 test\_db1/template/CrmCompany(\*\*ver 1)  
> > > > > hit: 0.126185 test\_db1/Person/W2.7(ver 1)  
> > > > > hit: 0.126185 test\_db1/Person/W2.8(ver 1)  
> > > > > hit: 0.126185 test\_db1/Person/W2.9(ver 1)  
> > > > > hit: 0.126185 test\_db1/Person/W2.10(ver 1)  
> > > > > hit: 0.126185 test\_db1/Person/W2.11(ver 1)  
> > > > > hit: 0.126185 test\_db1/Person/W2.12(ver 1)  
> > > > > hit: 0.126185 test\_db1/Person/W2.13(ver 1)  
> > > > > hit: 0.126185 test\_db1/Person/W2.14(ver 1)
> > > > > 
> > > > > {"title":"Person template","desc":"Person template","path":"/  
> > > > > test\_db1/template/CrmPerson"\*\*,"version":1},{"title":"Person  
> > > > > template","desc":"Person template","path":"/test\_db1/**template/  
> > > > > CrmCompany","version":1},{"title":"Steven Boutte","desc":"Contacts  
> > > > > person document containing details of Steven Boutte","path":"/  
> > > > > test\_db1/Person/W2.7","version":1},{"title":"Joe  
> > > > > Hunter","desc":"Contacts person document containing details of Joe  
> > > > > Hunter","path":"/test\_db1/Person/W2.8","version":1},  
> > > > > {"title":"Joseph Wells","desc":"Contacts person document containing  
> > > > > details of Joseph Wells","path":"/test\_db1/  
> > > > > Person/W2.9","version":  
> > > > > 1},{"title":"Albert Brown","desc":"Contacts person document containing  
> > > > > details of Albert Brown","path":"/test\_db1/  
> > > > > Person/W2.10","version":  
> > > > > 1},{"title":"Mike Rivera","desc":"Contacts person document containing  
> > > > > details of Mike Rivera","path":"/test\_db1/  
> > > > > Person/W2.11","version":  
> > > > > 1},{"title":"Sandra Hohl","desc":"Contacts person document containing  
> > > > > details of Sandra Hohl","path":"/test\_db1/**  
> > > > > Person/W2.12","version":  
> > > > > 1},{"title":"Curt Adamski","desc":"Contacts person document c  
> > > > > ontaining details of Curt Adamski","path":"/test\_db1/\*\*Person/  
> > > > > W2.13","version":1},{"title":"\*\*Darlene Quandt","desc":"Contacts  
> > > > > person  
> > > > > document containing details of Darlene Quandt","path":"/test\_db1/  
> > > > > Person/W2.14","version":1}
> > > > > 
> > > > > From the results above, I would like to filter those with title =  
> > > > > "Person template" or version = 1. But, I fail to do so provided the  
> > > > > codes below:
> > > > > 
> > > > > QueryBuilder qb =  
> > > > > QueryBuilders.queryString("\*\*Person");
> > > > > 
> > > > > AndFilterBuilder myFilters =  
> > > > > FilterBuilders.andFilter();  
> > > > > //  
> > > > > myFilters.add(FilterBuilders.\*\*termFilter("version", "1"));  
> > > > > myFilters.add(FilterBuilders.\*\*termFilter("title", "Person  
> > > > > template"));
> > > > > 
> > > > > // QueryBuilder qb =  
> > > > > QueryBuilders.filteredQuery(\*\*QueryBuilders.queryString(\*\*query),  
> > > > > myFilters);
> > > > > 
> > > > > // QueryBuilder qb =  
> > > > > QueryBuilders.filteredQuery(\*\*QueryBuilders.queryString(\*\*query),  
> > > > > // FilterBuilders.queryFilter( ... ));
> > > > > 
> > > > > searchResponse = client.prepareSearch(dbName)  
> > > > > .setSearchType(SearchType.\*\*QUERY\_THEN\_FETCH)  
> > > > > .setQuery(qb)  
> > > > > .setFilter(myFilters)  
> > > > > .setVersion(true)  
> > > > > .setFrom(start)  
> > > > > .setSize(size)  
> > > > > // .setExplain(true) // Explain hit score  
> > > > > // .setNoFields() // Do not return  
> > > > > stored fields  
> > > > > .addField("document.title")  
> > > > > .addField("document.desc")  
> > > > > .execute()  
> > > > > .actionGet();
> > > > > 
> > > > > Thanks,  
> > > > > Ariel
> > > > > 
> > > > > On Feb 1, 1:42 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > > > 
> > > > > Really hard to help without knowing what filter you use, the data you  
> > > > > index, and how its mapped...
> > > > > 
> > > > > On Tuesday, January 31, 2012 at 11:22 AM, Ariel Mendoza wrote:
> > > > > 
> > > > > I am using Java API for text search. Refer to the codes below, when I  
> > > > > execute it, no record is retrieve though the Filter parameters of  
> > > > > field and value pair I've set are correct, but when I comment-out or  
> > > > > remove the .setFilter(fb), the search works fine. Please let me know  
> > > > > if I'm doing this wrong or are there other approach to achieve my  
> > > > > goal?
> > > > > 
> > > > > searchResponse = client.prepareSearch(dbName)  
> > > > > .setSearchType(SearchType.\*\*QUERY\_THEN\_FETCH)  
> > > > > .setQuery(qb)  
> > > > > .setFilter(fb)  
> > > > > .setVersion(true)  
> > > > > .setFrom(start)  
> > > > > .setSize(size)  
> > > > > // .setExplain(true) // Explain hit score  
> > > > > // .setNoFields() // Do not return  
> > > > > stored fields  
> > > > > .addField("document.title")  
> > > > > .addField("document.desc")  
> > > > > .execute()  
> > > > > .actionGet();
> > > > 
> > > > --  
> > > > 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).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > 
> > > > --  
> > > > 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).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> > > Laitkor.infosolution pvt ltd
> > > 
> > > --  
> > > 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).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > 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).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> > Laitkor.infosolution pvt ltd
> 
> --  
> [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> Laitkor.infosolution pvt ltd
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
[mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
Laitkor.infosolution pvt ltd

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 19, 2013, 4:22pm UTC](https://discuss.elastic.co/t/remove-white-spaces-when-using-xcontentbuilder/10790/4 "2013-02-19T16:22:00Z")

</div>

What do you want to achieve here? Autocomplete?

What you should do is to find the right analyzer that fit your needs.  
If you need to do some autocomplete, have a look at EdgeNgram tokenizer: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/edgengram-tokenizer.html)

You can build your own analyzer using custom analyzer: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/custom-analyzer.html)  
You can define in this analyzer to break your tokens with a whitespace tokenizer [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/whitespace-tokenizer.html) or a standard tokenizer [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/standard-tokenizer.html)

It really depends on your use case.

What could help here to answer is to have a better idea of your use case and a full curl recreation (as a Gist).  
See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/)

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 19 févr. 2013 à 09:00, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit :

> This is my json
> 
> {  
> .....  
> "Education":" BCA","CurrentDesignation":" BCA",  
> "LastEmployer":" Ait",  
> "LastDesignation":" Developer",  
> "CurrentLocation":" Delhi",  
> "PreferredLocation":"Pune",  
> "Mobile": 88888...,  
> "Landline":" NotMentioned",  
> "Recommendations":" Not Mentioned",  
> "Lastmodifiedon":"11-Feb-2013"}}]}}
> 
> and when i search with  
> AndFilterBuilder queryFilters = FilterBuilders.andFilter();  
> queryFilters.add(FilterBuilders.prefixFilter("Education", "B"));
> 
> It will not give any Hits...but get Hits results only where value have no any whitespaces and its value in Lowercase
> 
> =================================================================
> 
> On Tue, Feb 19, 2013 at 12:13 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> The NPE is probably in your code:  
> emails.get(i).from.trim()
> 
> This is not relative to Elasticsearch.
> 
> That said, why do you think you need to remove white spaces?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 19 févr. 2013 à 06:19, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit :
> 
> Hello sir  
> I want to remove whitespaces and using trim()
> 
> ```
> XContentBuilder builder = XContentFactory.jsonBuilder()
> .startObject();
> 
> ```
> 
> builder.field("From", emails.get(i).from.trim());
> 
> but find :Exception in thread "main" java.lang.NullPointerException  
> and also Node not created
> 
> ============================================================
> 
> On Mon, Feb 18, 2013 at 4:36 PM, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) wrote:  
> Thanks sir for support
> 
> ====================================================================
> 
> On Mon, Feb 18, 2013 at 1:52 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> Prefix filter is not analyzed. See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/prefix-filter.html)
> 
> So, if you want to use it here, use it with a Capital N
> 
> --  
> David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> @dadoonet | @elasticsearchfr | @scrutmydocs
> 
> Le 18 févr. 2013 à 09:20, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit :
> 
> > yes i have CurrentLocation:Navi Mumbai  
> > ok i have change CurrentLocation:delhi but  
> > i think when we using prefixFilter than match with "null" if no any match found and should return result so My question still same why Filter not working when comments out than find result
> > 
> > # { "took" : 31, "timed\_out" : false, "\_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 0, "max\_score" : null, "hits" : } } so please suggest me how to search on the basis of skills and location with java api?
> > 
> > On Mon, Feb 18, 2013 at 12:24 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> > Do you have a document with CurrentLocation=n ?
> > 
> > Hard to say something else as we don't know your mapping either your docs.
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 18 févr. 2013 à 07:00, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit :
> > 
> > I have already facing same problem
> > 
> > Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "elasticsearch").build();  
> > Client client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("192.168.1.16", 9300));  
> > client.admin().indices().prepareRefresh("resume\_index").execute().actionGet();  
> > FilterBuilders.andFilter(  
> > FilterBuilders.prefixFilter("keyskil", "asp"),  
> > FilterBuilders.prefixFilter("CurrentLocation", "delhi")  
> > );  
> > AndFilterBuilder queryFilters = FilterBuilders.andFilter();  
> > queryFilters.add(FilterBuilders.prefixFilter("keyskil", "asp"));  
> > queryFilters.add(FilterBuilders.prefixFilter("CurrentLocation", "n"));  
> > FilterBuilder aggFilter = FilterBuilders.andFilter(queryFilters);  
> > SearchResponse response = client.prepareSearch("resume\_index")  
> > .setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
> > //.setFilter(aggFilter)  
> > //.setQuery(QueryBuilders.termQuery("KeySkills", "red"))  
> > //.setQuery(QueryBuilders.prefixQuery("CurrentLocation","n"))  
> > .setFrom(0)  
> > .setSize(2)  
> > .setExplain(true)  
> > .execute()  
> > .actionGet();
> > 
> > ```
> > System.out.println(response.toString());
> > String s=response.toString();
> > 
> > ```
> > 
> > find result:
> > 
> > {  
> > "took" : 0,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 261,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_shard" : 0,  
> > "\_node" : "Gik4Z040QSSzsNRlS9sVew",  
> > "\_index" : "resume\_index",  
> > "_type" : "emls_",  
> > "\_id" : "\<[CAFV6cM-pUaUTLFv-uDvTXHvYDHOV61vyQL5WdxAfiGLmBYkcLail.com](http://CAFV6cM-pUaUTLFv-uDvTXHvYDHOV61vyQL5WdxAfiGLmBYkcLail.com)\>",  
> > "\_score" : 1.0, "\_source" : {"From":"ajay.singh@com","Subject":"Fwd: check file parser","Path":"E:\emls\output\ajacom.lalituttam\_129.doc","ResumeHeadline":"[asp.net](http://asp.net) developerhaving 2 year and 5 months experience ","KeySkills":"[ASP.Net](http://ASP.Net) & C#.NetWith SQLServer 2005 ","Name":"saris kumar gupta ","TotalExperience":"2 Years, 1 Months ","CTC":"Rs1.45 lacs ","CurrentEmployer":"IAP Company Limited ","CurrentDesignation":"SoftwareProgrammer ","LastEmployer":null,"LastDesignation":null,"CurrentLocation":null,"PreferredLocation":null,"Education":"B.A, MCA ","Mobile":"7388852980 ","Landline":"91-- ","Recommendations":"Not Mentioned ","Lastmodifiedon":"14-Mar-2012 "},  
> > "\_explanation" : {  
> > "value" : 1.0,  
> > "description" : "ConstantScore(NotDeleted(_:_)), product of:",  
> > "details" : [ {  
> > "value" : 1.0,  
> > "description" : "boost"  
> > }, {  
> > "value" : 1.0,  
> > "description" : "queryNorm"  
> > } ]  
> > }  
> > }, {............................
> > 
> > but when //.setFilter(aggFilter) comments out then find result
> > 
> > # { "took" : 16, "timed\_out" : false, "\_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 0, "max\_score" : null, "hits" : } } please let me know whats the error? I want search on basis of multiple filed..
> > 
> > On Wednesday, February 1, 2012 3:10:11 PM UTC+5:30, kimchy wrote:  
> > Its probably because the title is analyzed, so its broken down into (modified) terms, for example, "Person template" will be broken down into two tokens, "person" and "template". When you use term filter, it only works on actual tokens. You can have the title not analyzed in the mapping (or use a multi field mapping that has it both as analyzed and not\_analyzed) and then filter on the not analyzed version of it.  
> > On Wednesday, February 1, 2012 at 2:35 AM, Ariel Mendoza wrote:
> > 
> > > Hi Shay,
> > > 
> > > I am using AndFilterBuilder. Here are the results when setFilter(fb)  
> > > is commented-out.
> > > 
> > > Search 'Person': took 68ms, shards 1:0  
> > > hit: 0.220823 test\_db1/template/CrmPerson(ver 1)  
> > > hit: 0.220823 test\_db1/template/CrmCompany(ver 1)  
> > > hit: 0.126185 test\_db1/Person/W2.7(ver 1)  
> > > hit: 0.126185 test\_db1/Person/W2.8(ver 1)  
> > > hit: 0.126185 test\_db1/Person/W2.9(ver 1)  
> > > hit: 0.126185 test\_db1/Person/W2.10(ver 1)  
> > > hit: 0.126185 test\_db1/Person/W2.11(ver 1)  
> > > hit: 0.126185 test\_db1/Person/W2.12(ver 1)  
> > > hit: 0.126185 test\_db1/Person/W2.13(ver 1)  
> > > hit: 0.126185 test\_db1/Person/W2.14(ver 1)
> > > 
> > > {"title":"Person template","desc":"Person template","path":"/  
> > > test\_db1/template/CrmPerson","version":1},{"title":"Person  
> > > template","desc":"Person template","path":"/test\_db1/template/  
> > > CrmCompany","version":1},{"title":"Steven Boutte","desc":"Contacts  
> > > person document containing details of Steven Boutte","path":"/  
> > > test\_db1/Person/W2.7","version":1},{"title":"Joe  
> > > Hunter","desc":"Contacts person document containing details of Joe  
> > > Hunter","path":"/test\_db1/Person/W2.8","version":1},  
> > > {"title":"Joseph Wells","desc":"Contacts person document containing  
> > > details of Joseph Wells","path":"/test\_db1/Person/W2.9","version":  
> > > 1},{"title":"Albert Brown","desc":"Contacts person document containing  
> > > details of Albert Brown","path":"/test\_db1/Person/W2.10","version":  
> > > 1},{"title":"Mike Rivera","desc":"Contacts person document containing  
> > > details of Mike Rivera","path":"/test\_db1/Person/W2.11","version":  
> > > 1},{"title":"Sandra Hohl","desc":"Contacts person document containing  
> > > details of Sandra Hohl","path":"/test\_db1/Person/W2.12","version":  
> > > 1},{"title":"Curt Adamski","desc":"Contacts person document c  
> > > ontaining details of Curt Adamski","path":"/test\_db1/Person/  
> > > W2.13","version":1},{"title":"Darlene Quandt","desc":"Contacts person  
> > > document containing details of Darlene Quandt","path":"/test\_db1/  
> > > Person/W2.14","version":1}
> > > 
> > > From the results above, I would like to filter those with title =  
> > > "Person template" or version = 1. But, I fail to do so provided the  
> > > codes below:
> > > 
> > > QueryBuilder qb =  
> > > QueryBuilders.queryString("Person");
> > > 
> > > AndFilterBuilder myFilters =  
> > > FilterBuilders.andFilter();  
> > > //  
> > > myFilters.add(FilterBuilders.termFilter("version", "1"));  
> > > myFilters.add(FilterBuilders.termFilter("title", "Person template"));
> > > 
> > > // QueryBuilder qb =  
> > > QueryBuilders.filteredQuery(QueryBuilders.queryString(query),  
> > > myFilters);
> > > 
> > > // QueryBuilder qb =  
> > > QueryBuilders.filteredQuery(QueryBuilders.queryString(query),  
> > > // FilterBuilders.queryFilter( ... ));
> > > 
> > > searchResponse = client.prepareSearch(dbName)  
> > > .setSearchType(SearchType.QUERY\_THEN\_FETCH)  
> > > .setQuery(qb)  
> > > .setFilter(myFilters)  
> > > .setVersion(true)  
> > > .setFrom(start)  
> > > .setSize(size)  
> > > // .setExplain(true) // Explain hit score  
> > > // .setNoFields() // Do not return  
> > > stored fields  
> > > .addField("document.title")  
> > > .addField("document.desc")  
> > > .execute()  
> > > .actionGet();
> > > 
> > > Thanks,  
> > > Ariel
> > > 
> > > On Feb 1, 1:42 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > 
> > > > Really hard to help without knowing what filter you use, the data you index, and how its mapped...
> > > > 
> > > > On Tuesday, January 31, 2012 at 11:22 AM, Ariel Mendoza wrote:
> > > > 
> > > > > I am using Java API for text search. Refer to the codes below, when I  
> > > > > execute it, no record is retrieve though the Filter parameters of  
> > > > > field and value pair I've set are correct, but when I comment-out or  
> > > > > remove the .setFilter(fb), the search works fine. Please let me know  
> > > > > if I'm doing this wrong or are there other approach to achieve my  
> > > > > goal?
> > > > 
> > > > > searchResponse = client.prepareSearch(dbName)  
> > > > > .setSearchType(SearchType.QUERY\_THEN\_FETCH)  
> > > > > .setQuery(qb)  
> > > > > .setFilter(fb)  
> > > > > .setVersion(true)  
> > > > > .setFrom(start)  
> > > > > .setSize(size)  
> > > > > // .setExplain(true) // Explain hit score  
> > > > > // .setNoFields() // Do not return  
> > > > > stored fields  
> > > > > .addField("document.title")  
> > > > > .addField("document.desc")  
> > > > > .execute()  
> > > > > .actionGet();
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> > Laitkor.infosolution pvt ltd
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> Laitkor.infosolution pvt ltd
> 
> --  
> [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> Laitkor.infosolution pvt ltd
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> Laitkor.infosolution pvt ltd
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mukesh](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mukesh](https://discuss.elastic.co/u/mukesh)\
**Post date:** [February 20, 2013, 3:37am UTC](https://discuss.elastic.co/t/remove-white-spaces-when-using-xcontentbuilder/10790/5 "2013-02-20T03:37:07Z")

</div>

Hello sir  
I want to search on the behalf of CurrentLocation and  
its Education from jsp page ....issues is that:

```
   String cl=getCurrentLocation(); Here we find the value of

```

currentlocation

1-..setQuery(QueryBuilders.prefixQuery("CurrentLocation",  
getCurrentLocation())) but here not getting the value ....  
Please Let me know, can we change the value at run time or  
not ?

===============================================================  
On Tue, Feb 19, 2013 at 9:52 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> What do you want to achieve here? Autocomplete?
> 
> What you should do is to find the right analyzer that fit your needs.  
> If you need to do some autocomplete, have a look at EdgeNgram tokenizer:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/edgengram-tokenizer.html)
> 
> You can build your own analyzer using custom analyzer:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/custom-analyzer.html)  
> You can define in this analyzer to break your tokens with a whitespace  
> tokenizer  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/whitespace-tokenizer.html) or  
> a standard tokenizer  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/standard-tokenizer.html)
> 
> It really depends on your use case.
> 
> What could help here to answer is to have a better idea of your use case  
> and a full curl recreation (as a Gist).  
> See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/)
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 19 févr. 2013 à 09:00, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit :
> 
> This is my json
> 
> {  
> .....  
> "Education":" BCA","CurrentDesignation":" BCA",  
> "LastEmployer":" Ait",  
> "LastDesignation":" Developer",  
> "CurrentLocation":" Delhi",  
> "PreferredLocation":"Pune",  
> "Mobile": 88888...,  
> "Landline":" NotMentioned",  
> "Recommendations":" Not Mentioned",  
> "Lastmodifiedon":"11-Feb-2013"}}]}}
> 
> and when i search with  
> AndFilterBuilder queryFilters = FilterBuilders.andFilter();  
> queryFilters.add(FilterBuilders.prefixFilter("Education",  
> "B"));
> 
> It will not give any Hits...but get Hits results only where value have no  
> any whitespaces and its value in Lowercase
> 
> =================================================================
> 
> On Tue, Feb 19, 2013 at 12:13 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > The NPE is probably in your code:  
> > emails.get(i).from.trim()
> > 
> > This is not relative to Elasticsearch.
> > 
> > That said, why do you think you need to remove white spaces?
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 19 févr. 2013 à 06:19, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit :
> > 
> > Hello sir  
> > I want to remove whitespaces and using trim()
> > 
> > ```
> > XContentBuilder builder = XContentFactory.jsonBuilder()
> > .startObject();
> > 
> > ```
> > 
> > builder.field("From", emails.get(i).from.trim());
> > 
> > but find :Exception in thread "main" java.lang.NullPointerException  
> > and also Node not created
> > 
> > ============================================================
> > 
> > On Mon, Feb 18, 2013 at 4:36 PM, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)wrote:
> > 
> > > Thanks sir for support
> > > 
> > > ====================================================================
> > > 
> > > On Mon, Feb 18, 2013 at 1:52 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> > > 
> > > > Prefix filter is not analyzed. See  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/prefix-filter.html)
> > > > 
> > > > So, if you want to use it here, use it with a Capital N
> > > > 
> > > > --  
> > > > _David Pilato_ | _Technical Advocate_ | \*[Elasticsearch.com](http://Elasticsearch.com)[http://elasticsearch.com/](http://elasticsearch.com/)  
> > > > \*  
> > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > > > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > > > 
> > > > Le 18 févr. 2013 à 09:20, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a écrit  
> > > > :
> > > > 
> > > > yes i have CurrentLocation:Navi Mumbai  
> > > > ok i have change CurrentLocation:delhi but  
> > > > i think when we using prefixFilter than match with "null"  
> > > > if no any match found and should return result so My question still same  
> > > > why Filter not working when comments out than find result
> > > > 
> > > > # { "took" : 31, "timed\_out" : false, "\_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 0, "max\_score" : null, "hits" : } } so please suggest me how to search on the basis of skills and location with java api?
> > > > 
> > > > On Mon, Feb 18, 2013 at 12:24 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> > > > 
> > > > > Do you have a document with CurrentLocation=n ?
> > > > > 
> > > > > Hard to say something else as we don't know your mapping either your  
> > > > > docs.
> > > > > 
> > > > > --  
> > > > > David 😉  
> > > > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > > > 
> > > > > Le 18 févr. 2013 à 07:00, MUKESH PANDEY [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com) a  
> > > > > écrit :
> > > > > 
> > > > > I have already facing same problem
> > > > > 
> > > > > Settings settings = ImmutableSettings.settingsBuilder().put("  
> > > > > cluster.name", "elasticsearch").build();  
> > > > > Client client = new  
> > > > > TransportClient(settings).addTransportAddress(new  
> > > > > InetSocketTransportAddress("192.168.1.16", 9300));
> > > > > 
> > > > > client.admin().indices().prepareRefresh("resume\_index").execute().actionGet();  
> > > > > FilterBuilders.andFilter(  
> > > > > FilterBuilders.prefixFilter("keyskil", "asp"),  
> > > > > FilterBuilders.prefixFilter("CurrentLocation", "delhi")  
> > > > > );  
> > > > > AndFilterBuilder queryFilters = FilterBuilders.andFilter();  
> > > > > queryFilters.add(FilterBuilders.prefixFilter("keyskil",  
> > > > > "asp"));
> > > > > 
> > > > > queryFilters.add(FilterBuilders.prefixFilter("CurrentLocation", "n"));  
> > > > > FilterBuilder aggFilter =  
> > > > > FilterBuilders.andFilter(queryFilters);  
> > > > > SearchResponse response =  
> > > > > client.prepareSearch("resume\_index")
> > > > > 
> > > > > .setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
> > > > > //.setFilter(aggFilter)
> > > > > 
> > > > > //.setQuery(QueryBuilders.termQuery("KeySkills", "red"))
> > > > > 
> > > > > //.setQuery(QueryBuilders.prefixQuery("CurrentLocation","n"))  
> > > > > .setFrom(0)  
> > > > > .setSize(2)  
> > > > > .setExplain(true)  
> > > > > .execute()  
> > > > > .actionGet();
> > > > > 
> > > > > ```
> > > > > System.out.println(response.toString());
> > > > > String s=response.toString();
> > > > > 
> > > > > ```
> > > > > 
> > > > > find result:
> > > > > 
> > > > > {  
> > > > > "took" : 0,  
> > > > > "timed\_out" : false,  
> > > > > "\_shards" : {  
> > > > > "total" : 5,  
> > > > > "successful" : 5,  
> > > > > "failed" : 0  
> > > > > },  
> > > > > "hits" : {  
> > > > > "total" : 261,  
> > > > > "max\_score" : 1.0,  
> > > > > "hits" : [ {  
> > > > > "\_shard" : 0,  
> > > > > "\_node" : "Gik4Z040QSSzsNRlS9sVew",  
> > > > > "\_index" : "resume\_index",  
> > > > > "_type" : "emls_",  
> > > > > "\_id" : "\<  
> > > > > [CAFV6cM-pUaUTLFv-uDvTXHvYDHOV61vyQL5WdxAfiGLmBYkcLail.com](http://CAFV6cM-pUaUTLFv-uDvTXHvYDHOV61vyQL5WdxAfiGLmBYkcLail.com)[http://cafv6cm-puautlfv-udvtxhvydhov61vyql5wdxafiglmbykclail.com/](http://cafv6cm-puautlfv-udvtxhvydhov61vyql5wdxafiglmbykclail.com/)
> > > > > 
> > > > > > ",  
> > > > > > "\_score" : 1.0, "\_source" : {"From":"ajay.singh@com","Subject":"Fwd:  
> > > > > > check file parser","Path":"E:\emls\output\ajacom.lalituttam\_129.doc  
> > > > > > ","ResumeHeadline":"[asp.net](http://asp.net) developerhaving 2 year and 5 months  
> > > > > > experience ","KeySkills":"[ASP.Net](http://ASP.Net) [http://asp.net/](http://asp.net/) & C#.NetWith  
> > > > > > SQLServer 2005 ","Name":"saris kumar gupta ","TotalExperience":"2 Years, 1  
> > > > > > Months ","CTC":"Rs1.45 lacs ","CurrentEmployer":"IAP Company Limited  
> > > > > > ","CurrentDesignation":"SoftwareProgrammer  
> > > > > > ","LastEmployer":null,"LastDesignation":null,"CurrentLocation":null,"PreferredLocation":null,"Education":"B.A,  
> > > > > > MCA ","Mobile":"7388852980 ","Landline":"91-- ","Recommendations":"Not  
> > > > > > Mentioned ","Lastmodifiedon":"14-Mar-2012 "},  
> > > > > > "\_explanation" : {  
> > > > > > "value" : 1.0,  
> > > > > > "description" : "ConstantScore(NotDeleted(_:_)), product of:",  
> > > > > > "details" : [ {  
> > > > > > "value" : 1.0,  
> > > > > > "description" : "boost"  
> > > > > > }, {  
> > > > > > "value" : 1.0,  
> > > > > > "description" : "queryNorm"  
> > > > > > } ]  
> > > > > > }  
> > > > > > }, {............................
> > > > > 
> > > > > but when //.setFilter(aggFilter) comments out then find result
> > > > > 
> > > > > {  
> > > > > "took" : 16,  
> > > > > "timed\_out" : false,  
> > > > > "\_shards" : {  
> > > > > "total" : 5,  
> > > > > "successful" : 5,  
> > > > > "failed" : 0  
> > > > > },  
> > > > > "hits" : {  
> > > > > "total" : 0,  
> > > > > "max\_score" : null,  
> > > > > "hits" :   
> > > > > }  
> > > > > } please let me know whats the error? I want search on basis of  
> > > > > multiple filed..
> > > > > 
> > > > > ============================================================================
> > > > > 
> > > > > On Wednesday, February 1, 2012 3:10:11 PM UTC+5:30, kimchy wrote:
> > > > > 
> > > > > > Its probably because the title is analyzed, so its broken down into  
> > > > > > (modified) terms, for example, "Person template" will be broken down into  
> > > > > > two tokens, "person" and "template". When you use term filter, it only  
> > > > > > works on actual tokens. You can have the title not analyzed in the mapping  
> > > > > > (or use a multi field mapping that has it both as analyzed and  
> > > > > > not\_analyzed) and then filter on the not analyzed version of it.
> > > > > > 
> > > > > > On Wednesday, February 1, 2012 at 2:35 AM, Ariel Mendoza wrote:
> > > > > > 
> > > > > > Hi Shay,
> > > > > > 
> > > > > > I am using AndFilterBuilder. Here are the results when setFilter(fb)  
> > > > > > is commented-out.
> > > > > > 
> > > > > > Search 'Person': took 68ms, shards 1:0  
> > > > > > hit: 0.220823 test\_db1/template/CrmPerson(\*\*ver 1)  
> > > > > > hit: 0.220823 test\_db1/template/CrmCompany(\*\*ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.7(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.8(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.9(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.10(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.11(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.12(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.13(ver 1)  
> > > > > > hit: 0.126185 test\_db1/Person/W2.14(ver 1)
> > > > > > 
> > > > > > {"title":"Person template","desc":"Person template","path":"/  
> > > > > > test\_db1/template/CrmPerson"\*\*,"version":1},{"title":"Person  
> > > > > > template","desc":"Person template","path":"/test\_db1/**template/  
> > > > > > CrmCompany","version":1},{"title":"Steven Boutte","desc":"Contacts  
> > > > > > person document containing details of Steven Boutte","path":"/  
> > > > > > test\_db1/Person/W2.7","version":1},{"title":"Joe  
> > > > > > Hunter","desc":"Contacts person document containing details of Joe  
> > > > > > Hunter","path":"/test\_db1/Person/W2.8","version":1},  
> > > > > > {"title":"Joseph Wells","desc":"Contacts person document containing  
> > > > > > details of Joseph Wells","path":"/test\_db1/  
> > > > > > Person/W2.9","version":  
> > > > > > 1},{"title":"Albert Brown","desc":"Contacts person document containing  
> > > > > > details of Albert Brown","path":"/test\_db1/  
> > > > > > Person/W2.10","version":  
> > > > > > 1},{"title":"Mike Rivera","desc":"Contacts person document containing  
> > > > > > details of Mike Rivera","path":"/test\_db1/  
> > > > > > Person/W2.11","version":  
> > > > > > 1},{"title":"Sandra Hohl","desc":"Contacts person document containing  
> > > > > > details of Sandra Hohl","path":"/test\_db1/**  
> > > > > > Person/W2.12","version":  
> > > > > > 1},{"title":"Curt Adamski","desc":"Contacts person document c  
> > > > > > ontaining details of Curt Adamski","path":"/test\_db1/\*\*Person/  
> > > > > > W2.13","version":1},{"title":"\*\*Darlene Quandt","desc":"Contacts  
> > > > > > person  
> > > > > > document containing details of Darlene Quandt","path":"/test\_db1/  
> > > > > > Person/W2.14","version":1}
> > > > > > 
> > > > > > From the results above, I would like to filter those with title =  
> > > > > > "Person template" or version = 1. But, I fail to do so provided the  
> > > > > > codes below:
> > > > > > 
> > > > > > QueryBuilder qb =  
> > > > > > QueryBuilders.queryString("\*\*Person");
> > > > > > 
> > > > > > AndFilterBuilder myFilters =  
> > > > > > FilterBuilders.andFilter();  
> > > > > > //  
> > > > > > myFilters.add(FilterBuilders.\*\*termFilter("version", "1"));  
> > > > > > myFilters.add(FilterBuilders.\*\*termFilter("title", "Person  
> > > > > > template"));
> > > > > > 
> > > > > > // QueryBuilder qb =  
> > > > > > QueryBuilders.filteredQuery(\*\*QueryBuilders.queryString(\*\*query),  
> > > > > > myFilters);
> > > > > > 
> > > > > > // QueryBuilder qb =  
> > > > > > QueryBuilders.filteredQuery(\*\*QueryBuilders.queryString(\*\*query),  
> > > > > > // FilterBuilders.queryFilter( ... ));
> > > > > > 
> > > > > > searchResponse = client.prepareSearch(dbName)  
> > > > > > .setSearchType(SearchType.\*\*QUERY\_THEN\_FETCH)  
> > > > > > .setQuery(qb)  
> > > > > > .setFilter(myFilters)  
> > > > > > .setVersion(true)  
> > > > > > .setFrom(start)  
> > > > > > .setSize(size)  
> > > > > > // .setExplain(true) // Explain hit score  
> > > > > > // .setNoFields() // Do not return  
> > > > > > stored fields  
> > > > > > .addField("document.title")  
> > > > > > .addField("document.desc")  
> > > > > > .execute()  
> > > > > > .actionGet();
> > > > > > 
> > > > > > Thanks,  
> > > > > > Ariel
> > > > > > 
> > > > > > On Feb 1, 1:42 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > > > > 
> > > > > > Really hard to help without knowing what filter you use, the data you  
> > > > > > index, and how its mapped...
> > > > > > 
> > > > > > On Tuesday, January 31, 2012 at 11:22 AM, Ariel Mendoza wrote:
> > > > > > 
> > > > > > I am using Java API for text search. Refer to the codes below, when I  
> > > > > > execute it, no record is retrieve though the Filter parameters of  
> > > > > > field and value pair I've set are correct, but when I comment-out or  
> > > > > > remove the .setFilter(fb), the search works fine. Please let me know  
> > > > > > if I'm doing this wrong or are there other approach to achieve my  
> > > > > > goal?
> > > > > > 
> > > > > > searchResponse = client.prepareSearch(dbName)  
> > > > > > .setSearchType(SearchType.\*\*QUERY\_THEN\_FETCH)  
> > > > > > .setQuery(qb)  
> > > > > > .setFilter(fb)  
> > > > > > .setVersion(true)  
> > > > > > .setFrom(start)  
> > > > > > .setSize(size)  
> > > > > > // .setExplain(true) // Explain hit score  
> > > > > > // .setNoFields() // Do not return  
> > > > > > stored fields  
> > > > > > .addField("document.title")  
> > > > > > .addField("document.desc")  
> > > > > > .execute()  
> > > > > > .actionGet();
> > > > > 
> > > > > --  
> > > > > 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).  
> > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > 
> > > > > --  
> > > > > 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).  
> > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > 
> > > > --  
> > > > [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> > > > Laitkor.infosolution pvt ltd
> > > > 
> > > > --  
> > > > 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).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > 
> > > > --  
> > > > 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).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> > > Laitkor.infosolution pvt ltd
> > 
> > --  
> > [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> > Laitkor.infosolution pvt ltd
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> [mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
> Laitkor.infosolution pvt ltd
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
[mukeshp073@gmail.com](mailto:mukeshp073@gmail.com)  
Laitkor.infosolution pvt ltd

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:50am UTC](https://discuss.elastic.co/t/remove-white-spaces-when-using-xcontentbuilder/10790/6 "2017-07-06T02:50:37Z")

</div>


