title: Elasticsearch Rails filter
body: <p>I am building Rails web app with elasticsearch-model gem. I would like to build search query with filtering for my Place model. I succeded in wrtiting search by name however I would like to be able to filter my search with city(In this example London).</p>
  
  <p>For now my query looks like this:</p>
  
  <pre><code>"query": {
      "bool": {
        "must": {
          "match": {
            "name": {
              "query": term,
              "operator": "and",
              "fuzziness": 1
            }
          }
        },
        "filter": {
            "term": {
                "city": "London"
            }
        }
      }
    }
  </code></pre>
  
  <p>and than I simple invoke <code>Place.search("here goes query").records.to_a</code></p>
  
  <p>without filter part search works fine, but when I add filter I don't get any result.</p>
  
  <p>This is mapping for Place search:</p>
  
  <pre><code>settings analysis: {
      filter: {
          ngram_filter: {
              type: "nGram",
              min_gram: 2,
              max_gram: 20
          }
      },
      analyzer: {
          ngram_analyzer: {
              type: "custom",
              tokenizer: "standard",
              filter: [
                  "lowercase",
                  "asciifolding",
                  "ngram_filter"
              ]
          },
          whitespace_analyzer: {
              type: "custom",
              tokenizer: "whitespace",
              filter: [
                  "lowercase",
                  "asciifolding"
              ]
          }
      }
  } do
    mappings dynamic: 'false' do
      indexes :name,
              type: "string",
              analyzer: "ngram_analyzer",
              search_analyzer: "whitespace_analyzer"
  </code></pre>
  
  <p>Here is the link I was using to see how to filter: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/2.4/breaking_20_query_dsl_changes.html#_queries_and_filters_merged" rel="nofollow">Elasticsearch doc</a></p>