Elasticsearch术语建议器返回结果

时间:2014-10-08 13:35:46

标签: search elasticsearch

为什么弹性搜索术语建议结果被阻止了? 当我这样做时:

curl -XPOST 'localhost:9200/posts/_suggest' -d '{
  "my-suggestion" : {
    "text" : "manger",
    "term" : {
       "field" : "body"
    }
  }
}'

预期的结果应该是“经理”,但我得到“manag”:

{
    "_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
            }]
        }
    }
}

1 个答案:

答案 0 :(得分:1)

术语汇总适用于"术语"通过标记化和词干化从原始文本制作。您需要将字段标记为" not_analyzed"在索引映射中禁用标记化和词干化。

我从未使用过建议者,但它认为您需要禁用该字段的词干,但启用标记化。索引中可以有两个版本的字段 - 一个用于搜索(标记化和词干化),另一个用于建议者(标记化但非梗塞)。