1

With the same record as below, I use many ways to filter to get it, I don't know why there are some way work and some way are NOT work. Is there anything I should concern

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

This is record which I get which the second two ways

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

Below is record mapping:

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

Below is analyzer:

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

2 Answers 2

3

If you want to use term filters on string make sure to change index as not_analyzed. But in this case full-text search won't work on this field. To make sure, both filters and full-text search to work change this field as multi-field. For example in the case of name, change the mapping to

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

And use name.not_analyzed for filtering.

Sign up to request clarification or add additional context in comments.

1 Comment

For recent Elasticsearch versions, you need to map { "type": "keyword" } or use name.keyword for filtering.
1

For me it helped to set the field type to keyword instead of string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.