時奇怪的搜索行爲所以我們可以說我有一個這樣定義的ElasticSearch指數: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"
}'
當我搜索「富企業」打雪仗分析,這兩個關鍵字匹配預期:
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"
]
}
}
]
}
}
我猜「吧」和「組織」之間的區別是,「組織」是朵朵給「器官」,而「巴」是源於自己。但是,如何獲得正確的行爲以便第二次搜索?
這很有道理,謝謝。有沒有一種方法可以查看我的索引具有的實際令牌?我能告訴ES爲** _ all **列使用雪球嗎? – tycooon 2012-03-15 07:01:38
沒有簡單的方法來查看索引中的實際令牌,但可以使用Analyze API查看如何分析文本(http://www.elasticsearch.org/guide/reference/api/admin-indices- analyze.html)。您可以在創建索引期間爲* _all *字段設置雪球分析器https://gist.github.com/2043721。或者,可以將雪球設置爲所有字段的默認分析器https://gist.github.com/2043697。 – imotov 2012-03-15 11:23:45