我已经尝试在给定的 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/