LoginSignup
4
4

More than 5 years have passed since last update.

Elasticsearchへの日本語データ投入と検索の方法(初級)

Last updated at Posted at 2015-08-14

前提:Kuromojiがインストールされていること。

アナライザの設定

curl -XPUT 'http://localhost:9200/tokyo' -d'
  {
      "index":{
          "analysis":{
              "tokenizer" : {
                  "kuromoji" : {
                     "type" : "kuromoji_tokenizer"
                  }
              },
              "analyzer" : {
                  "analyzer" : {
                      "type" : "custom",
                      "tokenizer" : "kuromoji"
                  }
              }
          }
      }
  }'

日本語データ入力

curl -XPUT http://localhost:9200/tokyo/shinagawa/1 -d '
{
    "title": "私の名前は大和です。",
    "content": "私は犬が好きです。",
    "tags": ["赤", "緑", "青"]
}
'

curl -XPUT http://localhost:9200/tokyo/shinagawa/2 -d '
{
    "title": "私の名前は田中です。",
    "content": "私は猫が好きです。",
    "tags": ["地球", "月", "火星"]
}
'

curl -XPUT http://localhost:9200/tokyo/shinagawa/3 -d '
{
    "title": "私の名前は渡辺です。",
    "content": "私は魚が好きです。",
    "tags": ["りんご", "みかん", "バナナ"]
}
'

検索

curl -XGET http://localhost:9200/tokyo/_search -d '
{
"query":
{ "match":{"title":"大和"}}
}'


curl -XGET http://localhost:9200/tokyo/_search -d '
{
"query":
{ "match":{"title":"田中"}}
}'


curl -XGET http://localhost:9200/tokyo/_search -d '
{
"query":
{ "match":{"title":"渡辺"}}
}'


curl -XGET http://localhost:9200/tokyo/_search -d '
{
"query":
{ "match":{"title":"私は"}}
}'


curl -XGET http://localhost:9200/tokyo/_search -d '
{
"query":
{ "match":{"tags":"バナナ"}}
}'

curl -XGET http://localhost:9200/tokyo/_search -d '
{
"query":
{ "match":{"title":"田中,大和"}}
}'
4
4
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
4
4