0

I want to add a custom set of stopwords to one particular field in a model. So I added a custom analyzer for that field. But still when I search with the stopwords, results are showing up. The code inside my model is as follows:

settings :analysis => {
 :filter  => {
  :stop_filter => {
    :type        => "stop",
    :stopwords   => ["how", "when", "where", "who", "which", "what", "do", "the", "a", "is", "to"]
  }
 },
 :analyzer => {
  :my_analyzer => {
    :type         => "standard",
    :filter       => "stop_filter",
    :tokenizer    => "standard"
  }
 }
} do
 mapping do
  indexes :id,              :type => 'integer',     :index    => :not_analyzed
  indexes :sortable_id,     :type => 'integer',     :index    => :not_analyzed
  indexes :summary,         :type => 'string',      :analyzer => 'my_analyzer'
 end
end

def self.search_all(search_string = nil, options = {})
  tire.search(:load => true, :page => options[:page] || 1, :per_page => options[:per_page] || 10) do
    query {search_string.present? ? string(search_string) : all}
    filter :term, {:topics_list_filter =>  options[:topic_id]} if options[:topic_id]
    sort {by options[:sort], options[:order] || 'desc'} if options[:sort].present?
  end
end

I have also tried by giving stopwords as an option in analyzer, without creating the stop_filter. I am not sure where I am going wrong.

deniro
  • 23
  • 5
  • How does your search_string look like? – imotov Nov 16 '12 at 12:25
  • curl -X GET "http://localhost:9200/project_development_192_168_7_13/question/_search?from=0&load=true&page=1&per_page=6&size=6&pretty=true" -d '{"query":{"query_string":{"query":"this is how"}},"filter":{"term":{"company_filter":1}},"size":6,"from":0}' - This is the query being fired. – deniro Nov 16 '12 at 12:45

2 Answers2

2

Your query is searching the _all field which is indexed using default analyzer. You can either replace the default field in your query with summary or replace the default analyzer. See How do I set the default analyzer for elastic search with tire? for more information.

Community
  • 1
  • 1
imotov
  • 28,277
  • 3
  • 90
  • 82
0

Have you reindexed your documents? I think your mapping criteria only gets sent to ElasticSearch when your documents are created and in some cases when your index is created.

stuartc
  • 2,244
  • 2
  • 24
  • 31