AnguillaJaponica / elasticsearch-exercise

0 stars 0 forks source link

mapping のカスタマイズ #6

Open d-mato opened 9 months ago

d-mato commented 9 months ago

elasticsearch-rails のデフォルトではなく、検索に必要なフィールドとそのタイプを指定して、トークナイザーなども個別に設定できるようにする。 (検索対象以外のテーブルもインデックスしたい場合でも mapping 定義が必要)

AnguillaJaponica commented 9 months ago

よーしもりもりやったるでーとこれ読みつつ考えてたんですが、どう進めましょうね:eyes:

https://opensearch.org/docs/latest/install-and-configure/plugins/ analysis-kuromojiいれて、Productモデルに

MAPPING = {
    settings: {
      analysis: {
        analyzer: {
          kuromoji_analyzer: {
            type: 'custom',
            tokenizer: 'kuromoji_tokenizer',
            filter: ...
          }
        }
      }
    },
    mappings: {
      properties: {
        name: {
          type: 'text',
          analyzer: 'kuromoji_analyzer'
        },
        category: {
          type: 'keyword' (全文としてインデックスしちゃっていいかあれですが)
        },
        average_rating: {
          type: 'float'
        },
        price: {
          type: 'float'
        }
      }
    }
  }.freeze

的にいれてく感じです??

d-mato commented 9 months ago

OpenSearch への組み込み方は知らないけど、 ES ではプラグインという位置づけなので、 Docker の起動コマンドでインストールするか、FDでやってたみたいに独自に Dockerfile を作る必要がありそうです。 kuromoji がデファクトスタンダードなのでいきなりいれてもいいですが、まずは標準の tokenizer でどの程度日本語の単語を認識できてるか試してみても良いかもしれませんね。