analyzer

standard一文字だけ
simpleスペース区切り
kuromoji日本語の形態素解析

analyzerの挙動確認

 curl 'localhost:9200/test/_analyze?pretty' -d 'こんにちは世界'
curl 'localhost:9200/test/_analyze?pretty=1&analyzer=my_ngram_analyzer' -d 'Database + fulltext=search'

参考サイト

  1. http://christina04.hatenablog.com/entry/2015/02/02/225734
  2. http://createfield.com/Elasticsearch%E3%81%AE%E3%82%A2%E3%83%8A%E3%83%A9%E3%82%A4%E3%82%B6%E3%83%BC%E3%82%92%E8%A9%A6%E3%81%99%E6%96%B9%E6%B3%95

mapping

mappingの基礎

UserAgentなどの用に空白で区切られた文字列をデフォルトで取り込むと解析されてしまい、ブラウザごとのシェアなどが正しく判定できない。全文一致のみ利用するのであればnot_analyzedを指定する。ただしそれだけだと今後は部分一致ができなくなるので部分一致用の設定も入れてあげる必要がある。Multi-Fieldと呼ばれていたが2.0以降ではやり方が違う。

"mappings": {
   "company": {
     "_source": {
       "enabled": true
     },
     "_all": {
       "enabled": true,
       "analyzer": "kuromoji_analyzer"
     },
     "properties": {
       "id": {
         "type": "integer",
         "index": "not_analyzed"
       },
       "name": {
         "type": "string",
         "index": "analyzed",
         "analyzer": "ngram_analyzer"
       },
       "location": {
         "type": "string",
         "index": "analyzed",
         "analyzer": "kuromoji_analyzer"
       }
     }
   },
   "project": {
     "_source": {
       "enabled": true
     },
     "_all": {
       "enabled": true,
       "analyzer": "kuromoji_analyzer"
     },
     "_parent": {
       "type": "company"
     },
     "properties": {
       "id": {
         "type": "integer",
         "index": "not_analyzed"
       },
       "title": {
         "type": "string",
         "index": "analyzed",
         "analyzer": "kuromoji_analyzer"
       }
     }
   }
 }

参考サイト

  1. http://engineer.wantedly.com/2014/02/25/elasticsearch-at-wantedly-1.html
Counter: 2656, today: 2, yesterday: 4

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS