Q:

Filter not working in JAVA API of elasticserach

curl 'http://10.176.140.117:9200/hed/courses/_search?q="WEEKEND"&fields=COURSE_TITLE,SCHEDULE_TYPE&pretty'  

Using this command in elasticsearch I am able to get the following response  
{
  "took": 7,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 5,
    "max_score": 0.019841569,
    "hits": [
      {
        "_index": "hed",
        "_type": "courses",
        "_id": "DtzBSU5iQtyYwpHpRghRUw",
        "_score": 0.019841569,
        "fields": {
          "SCHEDULE_TYPE": [
            "WEEKEND"
          ],
          "COURSE_TITLE": [
            "Creative Writing: Animals in Literature"
          ]
        }
      },
      {
        "_index": "hed",
        "_type": "courses",
        "_id": "ixyBLCZMQvSz4mimgtvsg",
        "_score": 0.019841569,
        "fields": {
          "SCHEDULE_TYPE": [
            "WEEKEND"
          ],
          "COURSE_TITLE": [
            "Professional Speeches for College Juniors"
          ]
        }
      },
      {
        "_index": "hed",
        "_type": "courses",
        "_id": "O1CW9t18RfmI7O1Egd4K0w",
        "_score": 0.016470294,
        "fields": {
          "SCHEDULE_TYPE": [
            "WEEKEND"
          ],
          "COURSE_TITLE": [
            "Creative Writing: Personal Essays and Creative Non Fiction"
          ]
        }
      },
      {
        "_index": "hed",
        "_type": "courses",
        "_id": "ilijmN7SDeROWtEYY2vLA",
        "_score": 0.0069672046,
        "fields": {
          "SCHEDULE_TYPE": [
            "WEEKEND"
          ],
          "COURSE_TITLE": [
            "Creative Writing: Insects in Literature"
          ]
        }
      },
      {
        "_index": "hed",
        "_type": "courses",
        "_id": "_f4NdWVnQPaszjgHgPGBRg",
        "_score": 0.0069672046,
        "fields": {
          "SCHEDULE_TYPE": [
            "WEEKEND"
          ],
          "COURSE_TITLE": [
            "Writing Lab"
          ]
        }
      }
    ]
  }
}

I need to filter out the set of documents which have "WEEKEND" in the "SCHEDULE_TYPE" field. I tried the same thing using JAVA API using the following code.
QueryBuilder matchAll = QueryBuilders.matchAllQuery();
FilterBuilder termfilter = FilterBuilders.termFilter("SCHEDULE_TYPE", "WEEKEND");    
SearchResponse searchResponse = client.prepareSearch("hed").addFields("COURSE_TITLE", "SCHEDULE_TYPE", "_score")
                .setTypes("courses").setQuery(matchAll).setPostFilter(termfilter).execute().actionGet();

But I am getting total hits as zero when I run the above code. Where is it going wrong?
UPDATE:
Below is a sample document from my indexed data
{
  "_index": "hed",
  "_type": "courses",
  "_id": "ilijm-N7SDeROWtEYY2vLA",
  "_score": 1,
  "_source": {
    "DURATION_TYPE": "Weeks",
    "CAMPUS": "MAINCAMPUS",
    "COURSE_FORMAT": "The source format is primarily reading (some aloud in class) and discussion. Student preparation before class is critical; external group meetings outside class time are encouraged! Assesment is based primarily on contributions to class discussions and quality of written works. The assignments will allow students to refine and develop their skills in writing and critique.",
    "INSTRUCTOR_PARTY_ID": 4365,
    "LAST_UPDATE_LOGIN": "-1",
    "COURSE_MODE": "INPERSON",
    "EFFORT_INVOLVED": "8-10 Hours of Work / Week",
    "PARTY_SITE_ID": null,
    "COURSE_OBJECTIVES": "<b>--Students will recognize the various forms of the genre </b>",
    "CREATED_BY": "SEED_DATA_FROM_APPLICATION",
    "COURSE_CD": "WRIT125",
    "SUBJECT_CATEGORY": null,
    "LAST_UPDATED_BY": "SEED_DATA_FROM_APPLICATION",
    "COURSE_RESOURCES": "<span style=\"color\": Gray; font-family: Arial, Helvetica, sans-serif;><u>Introduction to the Writing Process</u>, 2010 Edition; Sara Sandringham<br/>PhD.;http://www.amazon.com/books-used-books-textbooks/b?node=283155</span>",
    "SUBJECT_NAME": "English",
    "DURATION_COUNT": 14,
    "CERTIFICATION_FLAG": "N",
    "SCHEDULE_TYPE": "WEEKEND",
    "ACTIVE_FLAG": "Y",
    "VIDEO_INFO": "For nearly 20 years, Dr. James W. Pennebaker has been giving people an assignment: write down your deepest feelings about an emotional upheaval in your life for 15 or 20 minutes a day for four consecutive days",
    "DESCRIPTION": "This class is about insect portrayal in the classics.",
    "LAST_UPDATE_DATE": "2014-01-22T04:39:30.000Z",
    "CREATION_DATE": "2014-01-22T04:39:30.000Z",
    "COURSE_TITLE": "Creative Writing: Insects in Literature",
    "COURSE_INFO": "In this course for writers at all levels, study how several contemporary and classic authors created memorable works of fiction from their experience. By experimenting with techniques and experiences you can learn how to focus on dramatic moments of your own life, how to resurrect classic stories and how to structure the stories that are part of your life. Through subject selection, early drafts, revisions and final versions. Present nonfiction essays or chapters from a memoir for discussion and critique.",
    "CREDITS": 4,
    "INSTRUCTOR_NAME": "Francis Fernadas"
  }
}

A:

Default analzer means the tokens are lowercased and stored. So change the case of WEEKEND.try this
FilterBuilder termfilter = FilterBuilders.termFilter("SCHEDULE_TYPE", "weekend");

REFER
HOpe it helps..!

