php - 在 PHP 的 Elasticsearch 中使用建议器时出现非法参数异常

标签 php elasticsearch

我已经尝试在给定的 php 中实现完成建议查询 here .我的代码是:

$params = [
            "index" => $myIndex,
            "body" => [
                "try" => [
                    "text" => "ram",
                    "completion" => [ "value" => "suggest"]
                ]
            ]
        ];

        $response = $client->suggest($params);

我是这样做索引的:

$params = [
        "index" => $myIndex,
            "body" => [
            "settings"=> [
            "analysis"=> [
                "analyzer"=> [
                "start_with_analyzer"=> [
                    "tokenizer"=> "my_edge_ngram",
                    "filter"=> [
                    "lowercase"
                    ]
                ]
                ],
                "tokenizer"=> [
                "my_edge_ngram"=> [
                    "type"=> "edge_ngram",
                    "min_gram"=> 3,
                    "max_gram"=> 15
                ]
                ]
            ]
            ],
            "mappings"=> [
            "doc"=> [
                "properties"=> [
                "label"=> [
                    "type"=> "text",
                    "fields"=> [
                    "keyword"=> [
                        "type"=> "keyword"
                    ],
                    "ngramed"=> [
                        "type"=> "text",
                        "analyzer"=> "start_with_analyzer"
                    ]
                    ]
                ]
                ]
            ]
            ]
    ]
    ];
    $response = $client->indices()->create($params);    // create an index

我收到以下错误:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "[completion] unknown field [value], parser not found"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "[completion] unknown field [value], parser not found"
    },
    "status": 400
} 

我尝试将 value 更改为 value.keyword 但它显示相同的错误。我正在使用 Elasticsearch 5.3.2 。如何解决这个错误?

最佳答案

在查询中,您在完成中使用了字段“值”,但它不是这样的字段,这就是确切的错误说明。

您可以尝试以下解决方案:

    $params = [
                "index" => $myIndex,
                "body" => [
                    "try" => [
                        "text" => "ram",
                        "completion" => [ "label" => "suggest"]
                    ]
                ]
            ];
   $response = $client->suggest($params);

希望这会奏效。

关于php - 在 PHP 的 Elasticsearch 中使用建议器时出现非法参数异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56389356/

相关文章:

ruby - Logstash过滤出嵌套json数组中的键的值为空的值

elasticsearch - 仅获取 Kafka 消息的相关部分作为 Logstrash 的输入

php - 输出2时如何从第一行获取数据

php - 不显示 JSON 输出

amazon-web-services - Elasticsearch 6.3(AWS)快照还原进度错误: “/_recovery is not allowed”

java - 添加 `stdout` 后,LogStash JDBC 插件不会执行

lucene - 删除所有记录中的字段及其内容,并使用新映射重新创建它

php - 如何在 PHP 中生成(有点)安全密码?

php - Laravel 5.1 date_format 验证允许两种格式

javascript - 多个文件作为电子邮件附件上传