假设我有一个定义如下的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"
}'当我用snowball analyzer搜索"foo organizations“时,两个关键字都像预期的那样匹配:
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": []
}
}但是,如果我搜索“bar”,结果仍然是:
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"
]
}
}
]
}
}我猜"bar“和"organization”的区别在于,“组织”源于“器官”,而"bar“源于自身。但是,我如何获得正确的行为,以便第二次搜索命中?
发布于 2012-03-14 21:18:19
文本"foo bar organization“被索引两次-在字段 Text 和字段_all中。字段text使用snowball分析器,字段_all使用标准分析器。因此,在分析测试记录之后,字段_all包含标记:"foo“、"bar”和"organization“。在搜索过程中,指定的snowball分析器将"foo“转换为"foo",将"bar”转换为“bar”,将"organization“转换为”器官“。因此,查询中的单词"foo“和”bar“与测试记录匹配,而术语”组织“不匹配。突出显示是在每个字段基础上独立于搜索执行的,这就是为什么单词”组织“在第一个结果中突出显示的原因。
发布于 2014-03-06 23:52:49
最好在索引时使用分析器,而不是先将文本字段搜索到雪球分析器,然后再搜索time..Map。这将为组织创建一些令牌,其中包括organizations.It works for me
https://stackoverflow.com/questions/9700962
复制相似问题