elasticsearch,Filter,elasticsearch" /> elasticsearch,Filter,elasticsearch" />

Filter Elasticsearch筛选器不适用于字符串筛选器项

Filter Elasticsearch筛选器不适用于字符串筛选器项,filter,elasticsearch,Filter,elasticsearch,对于与下面相同的记录,我使用了许多方法来筛选它,我不知道为什么有些方法有效,有些方法无效。有什么我应该关心的吗 //not work: filtered: { query: {"match_all": {}}, filter: {"term" : { "name": "Road to Rio 2016"} } //not work: filtered: {

对于与下面相同的记录,我使用了许多方法来筛选它,我不知道为什么有些方法有效,有些方法无效。有什么我应该关心的吗

   //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"
             ]
          }

若要对字符串使用术语过滤器,请确保将索引更改为“未分析”。但在这种情况下,全文搜索在这个领域不起作用。为确保有效,过滤器和全文搜索都会将此字段更改为多字段。 例如,在名称的情况下,将映射更改为

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

并使用name.not_analysis进行筛选。

对我来说,将字段类型设置为
关键字
,而不是
字符串