search - Elasticsearch术语建议者返回词干结果

标签 search elasticsearch

为什么会阻止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/

相关文章:

linux - 如何在 linux 'screen' 中搜索任何单词

elasticsearch - 范围和短语查询在 elasticsearch 中如何工作?

json - 如何在Java中使用Elasticsearch jsonBuilder()?

c - 搜索字符串并将其与字符串数组进行比较

c - 如何在结构的链表中搜索字符串以不仅首先找到所有出现的地方?

javascript - 如何在字符串数组中搜索字符串

c - 在字符串大写 C 中制作特定单词

elasticsearch - Elasticsearch脚本查询无痛指数函数

elasticsearch - Kibana Watcher查询以搜索文本

Elasticsearch 聚合之聚合