したがって、ElasticSearchインデックスが次のように定義されているとしましょう。
curl -XPUT 'http://localhost:9200/test' -d '{
"mappings": {
"example": {
"properties": {
"text": {
"type": "string",
"analyzer": "snowball"
}
}
}
}
}'
curl -XPUT 'http://localhost:9200/test/example/1' -d '{
"text": "foo bar organization"
}'
スノーボールアナライザーで「foo組織」を検索すると、両方のキーワードが期待どおりに一致します。
curl -XGET http://localhost:9200/test/example/_search -d '{
"query": {
"text": {
"_all": {
"query": "foo organizations",
"analyzer": "snowball"
}
}
},
"highlight": {
"fields": {
"text": {}
}
}
}'
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.015912745,
"hits": [
{
"_index": "test",
"_type": "example",
"_id": "1",
"_score": 0.015912745,
"_source": {
"text": "foo bar organization"
},
"highlight": {
"text": [
"<em>foo</em> bar <em>organization</em>"
]
}
}
]
}
}
しかし、「組織」だけを検索すると、まったく結果が得られません。これは非常に奇妙なことです。
curl -XGET http://localhost:9200/test/example/_search -d '{
"query": {
"text": {
"_all": {
"query": "organizations",
"analyzer": "snowball"
}
}
},
"highlight": {
"fields": {
"text": {}
}
}
}'
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
ただし、「バー」を検索すると、次のようになります。
curl -XGET http://localhost:9200/test/example/_search -d '{
"query": {
"text": {
"_all": {
"query": "bars",
"analyzer": "snowball"
}
}
},
"highlight": {
"fields": {
"text": {}
}
}
}'
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.10848885,
"hits": [
{
"_index": "test",
"_type": "example",
"_id": "1",
"_score": 0.10848885,
"_source": {
"text": "foo bar organization"
},
"highlight": {
"text": [
"foo <em>bar</em> organization"
]
}
}
]
}
}
「バー」と「組織」の違いは、「組織」は「オルガン」に由来し、「バー」はそれ自体に由来するということだと思います。しかし、2番目の検索がヒットするように適切な動作を取得するにはどうすればよいですか?