Return specific fields for elasticsearch in rails
<p>This seems like a really easy issue, but everything I've tried from other solutions and websites is not working. I have three fields I do not want indexed or queried--<code>:p_s</code>, <code>:gender</code>, and <code>:part_of_speech</code>--but elasticsearch is still returning values from those fields even though I don't specify that they should be indexed or queried. About halfway down, <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-intro.html" rel="nofollow">this article</a> says to say <code>no</code> to indexing, but they don't indicate where this would occur. </p>

<p>Term Controller:</p>

<pre><code>  def search
    @terms = Term.search(params[:query]).page(params[:page])
  end
</code></pre>

<p>Model:</p>

<pre><code>require 'elasticsearch/model'

class Term &lt; ActiveRecord::Base

include Elasticsearch::Model
include Elasticsearch::Model::Callbacks

  settings index: { number_of_shards: 1, number_of_replicas: 0 },
    do

    mappings dynamic: 'false' do
      indexes :id, index: :not_analyzed
      indexes :name, analyzer: :spanish_analyzer
      indexes :definition, analyzer: :combined_analyzer
      indexes :etymology1, analyzer: :combined_analyzer
      indexes :etymology2, analyzer: :combined_analyzer
      indexes :uses, analyzer: :combined_analyzer
      indexes :notes1, analyzer: :combined_analyzer
      indexes :notes2, analyzer: :combined_analyzer
    end
  end

  def self.search(query)
    __elasticsearch__.search(
      {
        query: {
          multi_match: {
            query: query,
            fields: ['name^7', 'definition^6', 'etymology1^5', 'etymology2^4', 'uses^3', 'notes1^2', 'notes2^1'],
            operator: 'and'
          }
        }
      }
    )
  end
end

# Delete the previous term index in Elasticsearch
Term.__elasticsearch__.client.indices.delete index: Term.index_name rescue nil

# Create the new index with the new mapping
Term.__elasticsearch__.client.indices.create \
  index: Term.index_name,
  body: { settings: Term.settings.to_hash, mappings: Term.mappings.to_hash }

# Index all term records from the DB to Elasticsearch
Term.import(force: true)
</code></pre>