【问题标题】:Illegal Argument Exception when using Suggestors in Elasticsearch in PHP在 PHP 中的 Elasticsearch 中使用建议器时出现非法参数异常
【发布时间】:2019-05-31 15:56:36
【问题描述】:

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

$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,但它显示相同的错误。我正在使用弹性搜索 5.3.2 。如何解决这个错误?

【问题讨论】:

  • 能否在这里分享您的 Elasic Search 映射,这将有助于更好地理解问题。
  • @AmanGarg 我在问题中添加了这一点。

标签: php elasticsearch


【解决方案1】:

在查询中,您在补全中使用字段“值”,而它不是这样的字段,这就是确切的错误说明。

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

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

希望这会奏效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-01
    • 1970-01-01
    • 2022-07-07
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多