title: ElasticSearch - Using FilterBuilders
body: <p>I am new to ElasticSearch and Couchbase. I am building a sample Java application to learn more about ElasticSearch and Couchbase.</p>
  
  <p>Reading the <a href="http://www.elasticsearch.org/guide/reference/query-dsl/">ElasticSearch Java API</a>,  Filters are better used in cases where sort on score is not necessary and for caching.
  I still haven't figured out how to use FilterBuilders and have following questions:</p>
  
  <ul>
  <li>Can <code>FilterBuilders</code> be used alone to search?  </li>
  <li>Or Do they always have to be used with a <code>Query</code>? ( If true, can someone please list an example? )</li>
  <li>Going through a documentation, if I want to perform a search based on field values and want to use FilterBuilders, how can I accomplish that? (using <code>AndFilterBuilder</code> or <code>TermFilterBuilder</code> or <code>InFilterBuilder</code>? I am not clear about the differences between them.)</li>
  </ul>
  
  <p>For the 3rd question, I actually tested it with search using queries and using filters as shown below.
  I got empty result (no rows) when I tried search using <code>FilterBuilders</code>. I am not sure what am I doing wrong.</p>
  
  <p>Any examples will be helpful. I have had a tough time going through documentation which I found sparse and even searching led to various unreliable user forums.</p>
  
  <pre><code>private void processQuery() {
          SearchRequestBuilder srb = getSearchRequestBuilder(BUCKET);
          QueryBuilder qb = QueryBuilders.fieldQuery("doc.address.state", "TX");
          srb.setQuery(qb);
  
          SearchResponse resp = srb.execute().actionGet();
          System.out.println("response :" + resp);
      }
  
  private void searchWithFilters(){
          SearchRequestBuilder srb = getSearchRequestBuilder(BUCKET);
          srb.setFilter(FilterBuilders.termFilter("doc.address.state", "tx"));
          //AndFilterBuilder andFb = FilterBuilders.andFilter();
          //andFb.add(FilterBuilders.termFilter("doc.address.state", "TX")); 
          //srb.setFilter(andFb);
          SearchResponse resp = srb.execute().actionGet();
          System.out.println("response :" + resp);
      }
  </code></pre>
  
  <p>-<strong>-UPDATE--</strong></p>
  
  <p>As suggested in the answer, changing to lowercase "tx" works. With this question resolved. I still have following questions:</p>
  
  <ul>
  <li>In what scenario(s), are filters used with query? What purpose will this serve?</li>
  <li>Difference between <code>InFilter</code>, <code>TermFilter</code> and <code>MatchAllFilter</code>. Any illustration will help.</li>
  </ul>