elasticsearch,Java,elasticsearch" /> elasticsearch,Java,elasticsearch" />

elasticserach的JAVA API中的筛选器不工作

elasticserach的JAVA API中的筛选器不工作,java,elasticsearch,Java,elasticsearch,在elasticsearch中使用此命令,我能够得到以下响应 curl 'http://10.176.140.117:9200/hed/courses/_search?q="WEEKEND"&fields=COURSE_TITLE,SCHEDULE_TYPE&pretty' 我需要过滤掉“SCHEDULE_TYPE”字段中包含“WEEKEND”的文档集。我使用以下代码使用JavaAPI做了同样的尝试 { "took": 7, "timed_out": false,

在elasticsearch中使用此命令,我能够得到以下响应

curl 'http://10.176.140.117:9200/hed/courses/_search?q="WEEKEND"&fields=COURSE_TITLE,SCHEDULE_TYPE&pretty'  
我需要过滤掉“SCHEDULE_TYPE”字段中包含“WEEKEND”的文档集。我使用以下代码使用JavaAPI做了同样的尝试

{
  "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"
          ]
        }
      }
    ]
  }
}
但是当我运行上面的代码时,我得到的总命中率为零。哪里出了问题

更新: 下面是我的索引数据中的一个示例文档

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();
{
“_索引”:“hed”,
“_类型”:“课程”,
“_id”:“ilijm-N7SDeROWtEYY2vLA”,
“_分数”:1,
“_来源”:{
“持续时间类型”:“周”,
“校园”:“主校园”,
“课程格式”:“源格式主要是阅读(有些在课堂上大声朗读)和讨论。学生课前准备至关重要;鼓励课外小组会议!评估主要基于对课堂讨论的贡献和书面作品的质量。作业将允许学生改进和发展他们的写作和评论技能。”,
“讲师聚会ID”:4365,
“上次更新登录”:“-1”,
“课程模式”:“个人”,
“涉及的工作量”:“每周工作8-10小时”,
“参与方站点ID”:空,
“课程目标”:“学生将认识到该类型的各种形式”,
“创建人”:“从应用程序中获取种子数据”,
“课程光盘”:“书面125”,
“主题类别”:空,
“上次更新者”:“来自应用程序的种子数据”,
“课程资源”:“写作过程简介,2010年版;Sara Sandringham
博士。;http://www.amazon.com/books-used-books-textbooks/b?node=283155", “学科名称”:“英语”, “持续时间计数”:14, “认证标志”:“N”, “日程安排类型”:“周末”, “活动_标志”:“Y”, “视频信息”:“近20年来,James W.Pennebaker博士一直在给人们布置一项任务:连续四天每天15或20分钟,写下你对生活中情感剧变的最深感受”, “描述”:“本课程是关于经典作品中昆虫的描绘。”, “上次更新日期”:“2014-01-22T04:39:30.000Z”, “创建日期”:“2014-01-22T04:39:30.000Z”, “课程名称”:“创造性写作:文学中的昆虫”, “课程信息”:"在这门面向各级作家的课程中,学习几位当代和经典作家如何从他们的经历中创作出令人难忘的小说作品。通过技术和经验的实验,你可以学习如何专注于自己生活中的戏剧性时刻,如何复活经典故事,以及如何构建属于你生活的故事我们的生活。通过选题、初稿、修订和最终版本。呈现回忆录中的非小说类文章或章节,供讨论和评论。”, “学分”:4, “讲师姓名”:“弗朗西斯·费纳达斯” } }
默认Analyzer意味着令牌是小写的,并且是存储的。所以请更改WEEKEND的大小写。试试这个

{
  "_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"
  }
}


希望有帮助。

我看到了-在计划类型字段之前。它是否拼写正确?这是Postman REST客户端提供的。这很好。当我对计划类型进行查询而不是筛选时。我能够得到结果!你能发布你的索引映射吗?我没有使用自定义映射。我正在发布一个文档。Thanx很多!!它帮助……)
FilterBuilder termfilter = FilterBuilders.termFilter("SCHEDULE_TYPE", "weekend");