akmalcm
akmalcm

Reputation: 75

Elasticsearch inaccurate score for symbol searching

I've two stores named, face- and face+ store

when I search for face+, i want the list of results to be:

  1. face+ store
  2. face-

But, the results are

  1. face-
  2. face+ store

My custom analyzer will produce tokens like this

face- to [face, face-]

face+ store to [face, face+, +store, store]

this is my query

multi_match: {
  query: keywords,
  type: "best_fields",
  fields: ['name.analyzed^10','name.word_middle^5'],
  analyzer: "custom_analyzer",
}

this is my mapping, if it helps

analysis: {
  analyzer: {
    custom_analyzer: {
      type: "custom",
      char_filter: ["ampersand", "sym_repl"],
      tokenizer: "whitespace",
      filter: ["lowercase", "asciifolding", "searchkick_index_shingle", "searchkick_stemmer", "del_sym"]
    }
  },
  char_filter: {
    # adding a space between those patterns
    sym_repl: {
      type: "pattern_replace",
      pattern: '[.+\-*|\]\)\"#@&!]',
      replacement: " $0 "
    }
  },
  filter: {
    # remove token that match the stopwords
    del_sym: {
      type: "stop",
      stopwords: ['.', '+', '-', '*', '|', ']', ')', '"', '#', '@', '&', '!']
    }
  }
}

mappings: {
  store: {
    properties: {
      name: {
        type: "keyword",
        fields: {
          analyzed: {
            type: "text",
            analyzer: "custom_analyzer"
          }
        }
      },

Upvotes: 0

Views: 32

Answers (1)

Amit
Amit

Reputation: 32386

Its difficult to produce your issue, as you are using searchkick. but if you use minimum_should_matchwith value 2 and create a proper query, it will filterface-` from the search result and that is what you want.

Upvotes: 0

Related Questions