1

Elasticsearchで、最初の 4 文字と最後の 4 文字がトークン化される検索アナライザーを指定したいと考えています。

For example: supercalifragilisticexpialidocious => ["supe", "ious"]

次のようにngramを試してみました

PUT my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "my_tokenizer"
        }
      },
      "tokenizer": {
        "my_tokenizer": {
          "type": "ngram",
          "min_gram": 4,
          "max_gram": 4
        }
      }
    }
  }
}

次のようにアナライザーをテストしています

POST my_index/_analyze
{
  "analyzer": "my_analyzer",
  "text": "supercalifragilisticexpialidocious."
}

そして、「スーパー」を取り戻します...私が望まない「シャス」なものがたくさんあります。私にとっての問題は、上記で指定された ngram トークナイザーから最初と最後の結果のみを取得するにはどうすればよいですか?

{
  "tokens": [
    {
      "token": "supe",
      "start_offset": 0,
      "end_offset": 4,
      "type": "word",
      "position": 0
    },
    {
      "token": "uper",
      "start_offset": 1,
      "end_offset": 5,
      "type": "word",
      "position": 1
    },
...
    {
      "token": "ciou",
      "start_offset": 29,
      "end_offset": 33,
      "type": "word",
      "position": 29
    },
    {
      "token": "ious",
      "start_offset": 30,
      "end_offset": 34,
      "type": "word",
      "position": 30
    },
    {
      "token": "ous.",
      "start_offset": 31,
      "end_offset": 35,
      "type": "word",
      "position": 31
    }
  ]
}
4

1 に答える 1