为什么会阻止elasticsearch术语建议者结果?
当我执行此查询时:
curl -XPOST 'localhost:9200/posts/_suggest' -d '{
"my-suggestion" : {
"text" : "manger",
"term" : {
"field" : "body"
}
}
}'
预期的结果应该是“经理”,但我得到了“经理”:
{
"_shards":{
"total":5,
"successful":5,
"failed":0
},
"my-suggest-1":[
{
"text":"mang",
"offset":0,
"length":6,
"options":[
{
"text":"manag",
"score":0.75,
"freq":180
},
{
"text":"mani",
"score":0.75,
"freq":6
}
]
}
]
}
编辑
我为我的问题找到了解决方案:我在查询中添加了标准分析仪。
curl -XPOST 'localhost:9200/posts/_suggest' -d '{
"my-suggestion" : {
"text" : "manger",
"term" : {
"analyzer" : "standard",
"field" : "body"
}
}
}'
现在结果很好:
{
"_shards":{
"total":5,
"successful":5,
"failed":0
},
"my-suggest":[
{
"text":"mang",
"offset":0,
"length":6,
"options":[
{
"text":"manager",
"score":0.75,
"freq":180
},
{
"text":"manuel",
"score":0.75,
"freq":6
}
]
}
]
}
但是我遇到了另一个类似的聚合问题:
{
"aggs" : {
"cities" : {
"terms" : { "field" : "location" }
}
}
}
我得到的结果被修剪:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 473,
"max_score": 0.0,
"hits": []
},
"aggregations": {
"cities": {
"buckets": [{
"key": "londr",
"doc_count": 244
}, {
"key": "pari",
"doc_count": 244
}, {
"key": "tang",
"doc_count": 12
}, {
"key": "agad",
"doc_count": 8
}]
}
}
}
最佳答案
术语聚合适用于通过术语化和词干从原始文本中生成的“术语”。您需要在索引映射中将字段标记为“not_analyzed”以禁用标记化和词干。
我从未使用过建议程序,但它认为您需要禁用该字段的词干,但要启用标记化。您可以在索引中使用两种版本的字段-一种用于搜索(标记和词干),另一种用于建议者(标记,但没有词干)。
关于search - Elasticsearch术语建议者返回词干结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26258290/