Elasticsearch 过滤器不适用于字符串过滤器术语

Elasticsearch filter is not work with string filter term

同下面的记录,我用了很多方法筛选得到,不知道为什么有的方法可以,有的方法不行。有什么需要注意的吗

   //not work:  
     filtered: {
                 query: {"match_all": {}},
                 filter: {"term" : {  "name": "Road to Rio 2016"}
     }

  //not work:
    filtered: {
                 query: {"match_all": {}},
                 filter: {"term" : {   "isTemplate": "N"}
    }

  //work:
    filtered: {
                query: {"match_all": {}},
                filter: {"term" : { "teamId": 147}
     }

  //work:
        filtered: {
                    query: {"match_all": {}},
                    filter: {"term" : { "programId": 12615}
         }

这是我通过后两种方式得到的记录

 "hits": [
      {
        "_index": "bridge_tracker_cli_v0.0.7",
        "_type": "program",
        "_id": "12615",
        "_score": null,
        "_source": {
          "programId": 12615,
          "sportId": null,
          "name": "Road to Rio 2016",
          "description": "Program Overview",
          "isTemplate": "N",
          "editedById": 2170,
          "createdById": 1491,
          "clonedFromProgramId": 12608,
          "teamId": 147,
          "organizationId": 117,
          "createdAt": "2015-02-26T07:45:50.000Z",
          "updatedAt": "2015-04-13T04:47:41.000Z"
        },
        "sort": [
          1424936750000
        ]
      },

下面是记录映射:

 "_all": {
        "index_analyzer": "nGram_analyzer",
        "search_analyzer": "whitespace_analyzer"
      },

  "properties": {
    "clonedFromProgramId": {
      "type": "long",
      "include_in_all": false
    },
    "createdAt": {
      "type": "date",
      "format": "dateOptionalTime",
      "include_in_all": false
    },
    "createdById": {
      "type": "long",
      "include_in_all": false
    },
    "createdByScope": {
      "type": "string",
      "include_in_all": false
    },
    "dateEdit": {
      "type": "date",
      "format": "dateOptionalTime",
      "include_in_all": false
    },
    "description": {
      "type": "string"
    },
    "editedById": {
      "type": "long",
      "include_in_all": false
    },
    "editedByScope": {
      "type": "string",
      "include_in_all": false
    },
    "isTemplate": {
      "type": "string"
      "include_in_all": false
    },
    "name": {
      "type": "string"
    },
    "organizationId": {
      "type": "long",
      "include_in_all": false
    },
    "programId": {
      "type": "long"
    },
    "updatedAt": {
      "type": "date",
      "format": "dateOptionalTime",
      "include_in_all": false
    }
  }

下面是分析器:

 "analysis": {
        "filter": {
          "nGram_filter": {
             "type": "nGram",
             "min_gram": 1,
             "max_gram": 20,
             "token_chars": [
                "letter",
                "digit",
                "punctuation",
                "symbol"
             ]
          }
       },
       "analyzer": {
          "nGram_analyzer": {
             "type": "custom",
             "tokenizer": "whitespace",
             "filter": [
                "lowercase",
                "asciifolding",
                "nGram_filter"
             ]
          },
          "whitespace_analyzer": {
             "type": "custom",
             "tokenizer": "whitespace",
             "filter": [
                "lowercase",
                "asciifolding"
             ]
          }

如果您想对字符串使用术语过滤器,请确保将索引更改为 not_analyzed。但在这种情况下,全文搜索将无法在该字段上工作。为确保有效,过滤器和全文搜索都将此字段更改为多字段。 例如在 name 的情况下,将映射更改为

"name":{
          "type": "string",
          "fields": {
            "not_analyzed":{
              "index": "not_analyzed"
            }
          }
        }

并使用 name.not_analyzed 进行过滤。

对我来说,将字段类型设置为 keyword 而不是 string