2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Elastic Search: Prefix Queryでは解析が行われないよ

Posted at
simple_query_string: {
  query: "#{query}*", # <- 語尾の * に注目
  fields: %w(name, name_k eyword),
  default_operator: :OR
}

ここでは、 simple_query_string を用いているが syntax として * 利用している。
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html#simple-query-string-query-notes
simple query string syntaxの説明として、

  • at the end of a term signifies a prefix query

単語の最後にある * は、 prefix queryを示している。
と説明がある。

このprefix query、結構罠があって通常 Tokenizer に指定した方法で文字列が token化されると思うが、prefix queryの場合 not analyzed な query らしくトークン化の処理が行われない。
https://christina04.hatenablog.com/entry/2016/05/13/120413

トークン化が行われないということで、上の記事を見る感じ token filterも適用されないみたい。

ただし、character filterは行われる。(今回例を載せないが、実装してみた時に確認済み)
こういうケースも踏まえて token filter と character filterは厳密に使い分けたほうが良いなと思った。

特に、pattern replace は token filter にも character filterにも存在する。

どっちに書いても同じっしょっていうノリで使ってしまうと予想外な検索結果になるかも?

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?