2

クロモジ プラグイン 1.4.0 で Elasticsearch 0.90.1 を使用しています。

$ curl localhost:9200
{
  "ok" : true,
  "status" : 200,
  "name" : "Agent Zero",
  "version" : {
    "number" : "0.90.1",
    "snapshot_build" : false,
    "lucene_version" : "4.3"
  },
  "tagline" : "You Know, for Search"
}

defaultアナライザーに Kuromoji を使用して、新しいインデックスを作成します。

$ curl -X PUT localhost:9200/test -d '{
  "index": {
    "analysis": {
      "filter": {
        "kuromoji_rf": {
          "type": "kuromoji_readingform",
          "use_romaji": "false"
        }
      },
      "tokenizer": {
        "kuromoji": {
          "type": "kuromoji_tokenizer"
        }
      },
      "analyzer": {
        "default": {
          "type": "custom",
          "tokenizer": "kuromoji",
          "filter": [
            "kuromoji_rf"
          ]
        }
      }
    }
  }
}'

結果:

{
  "ok": true,
  "acknowledged": true
}

読み形トークン フィルターは正常に動作しているようです (漢字はカタカナに正規化されています)。

$ curl localhost:9200/test/_analyze -d '東京'

結果:

{
  "tokens": [
    {
      "token": "トウキョウ",
      "start_offset": 0,
      "end_offset": 2,
      "type": "word",
      "position": 1
    }
  ]
}

ドキュメントにインデックスを付ける:

$ curl -X PUT localhost:9200/test/docs/1 -d '{
  "body": "これは関西国際空港です"
}'

結果:

{
  "ok": true,
  "_index": "test",
  "_type": "docs",
  "_id": "1",
  "_version": 1
}%

インデックス付きドキュメントは、ワイルドカード クエリに一致します。

$ curl 'localhost:9200/test/docs/_search?q=body:*'

結果:

{
  "took": 109,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1.0,
    "hits": [
      {
        "_index": "test",
        "_type": "docs",
        "_id": "1",
        "_score": 1.0,
        "_source": {
          "body": "これは関西国際空港です"
        }
      }
    ]
  }
}

ただし、日本語を使用して検索すると一致しません。

$ curl 'localhost:9200/test/docs/_search?q=body:空港'

結果:

{
  "took": 21,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

$ curl 'localhost:9200/test/docs/_search?q=body:クウコウ'

結果:

{
  "took": 95,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

$ curl 'localhost:9200/test/docs/_search?q=body:空'

結果:

{
  "took": 22,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

アナライザーが検索クエリに使用されていないのではないかと思いましたが、アナライザーを指定しても役に立ちません。

$ curl 'localhost:9200/test/docs/_search?analyzer=default&q=body:空港'

結果:

{
  "took": 17,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

ちなみに、トークン フィルターを無効にすると、すべて正常に動作します。

私は何を間違っていますか?

4

1 に答える 1