带有标准分析器和编号的Elasticsearch完成建议

时间:2019-05-14 10:17:19

标签: elasticsearch

尝试使用标准分析器在完成字段上索引数字时出现错误。

映射:

PUT music
{
    "mappings": {
        "_doc" : {
            "properties" : {
                "suggest" : {
                    "type" : "completion",
                    "analyzer": "standard"
                }
            }
        }
    }
}

索引:

PUT music/_doc/1?refresh
{
  "suggest" : [ 1234, 5678 ]
}

这是我得到的错误:

[parsing_exception] failed to parse [null]: expected text or object, but got VALUE_NUMBER

我必须输入字符串吗?

1 个答案:

答案 0 :(得分:2)

您只需要将数字放在双引号(即字符串)中

PUT music/_doc/1?refresh
{
  "suggest" : [ "1234", "5678" ]
                ^    ^  ^    ^
                |    |  |    |
                 here and here
}