Я пытаюсь создать собственный анализатор для запросов к моему индексу эластичного поиска. Я использую PHP для веб-интерфейса. Вот мой код в файле fetch_nptel. php, который извлекает данные из индекса:
<?php
//fetch_nptel.php
session_start();
require_once '../vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->setHosts(['127.0.0.1:9200'])->build();
$output = '';
if(isset($_POST["query"]))
{
$link='';
$search = $_POST["query"];
$query = $client->search([
'settings' => [
'analysis' => [
'analyzer' => [
'my_custom_analyzer' => [
'type' => 'custom',
'tokenizer' => 'my_tokenizer',
'char_filter' => [
'html_strip'
],
'filter' => [
'lowercase',
'asciifolding'
]
]
],
'tokenizer' => [
'my_tokenizer' => [
'type' => 'edge_ngram',
'min_gram' => 1,
'max_gram' => 10,
'token_chars' => [
'letter',
'digit'
]
]
]
]
],
'body' => [
'query' => [
'bool' => [
'must' => [
'multi_match' => [
//"fuzziness" => "AUTO",
'analyzer' => 'my_custom_analyzer',
'fields' => ['title','link','description'],
'query' => $search
]
]
]
],
'from' => 0,
'size' => 100
]
]);
if($query['hits']['total']>=1){
$results = $query['hits']['hits'];
}
}
if(isset($results))
{
$output .= '
<div>Data found:</div>
';
foreach($results as $r)
{
if(isset($r["_source"]["link"])){
$link = $r["_source"]["link"];
$output .='
<div>'.$r["_source"]["title"].'</div>
<div>'.$r["_source"]["description"].'</div>
<div style="color:blue;"><a href="' . $link . '">'.$r["_source"]["link"].'</a></div>
';
}
}
echo $output;
}
else
{
echo 'Data Not Found';
}
?>
При запуске файла я получаю эту ошибку:
Fatal error: Uncaught Elasticsearch\Common\Exceptions\UnexpectedValueException: "settings" is not a valid parameter. Allowed parameters are "_source", "_source_excludes", "_source_includes", "allow_no_indices", "allow_partial_search_results", "analyze_wildcard", "analyzer", "batched_reduce_size", "ccs_minimize_roundtrips", "default_operator", "df", "docvalue_fields", "error_trace", "expand_wildcards", "explain", "filter_path", "from", "human", "ignore_throttled", "ignore_unavailable", "lenient", "max_concurrent_shard_requests", "opaqueId", "pre_filter_shard_size", "preference", "pretty", "q", "request_cache", "rest_total_hits_as_int", "routing", "scroll", "search_type", "seq_no_primary_term", "size", "sort", "source", "stats", "stored_fields", "suggest_field", "suggest_mode", "suggest_size", "suggest_text", "terminate_after", "timeout", "track_scores", "track_total_hits", "typed_keys", "version" in C:\xampp\htdocs\sgp\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Endpoints\AbstractEndpoint.php:235 Stack trace: #0 C in C:\xampp\htdocs\sgp\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Endpoints\AbstractEndpoint.php on line 235
Кажется, я не могу определить мой пользовательский анализатор во время запросов. Итак, как я могу разработать собственный анализатор для моего запроса? Это отображение индекса (nptel):
{
"mapping": {
"properties": {
"COURSE LAYOUT": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"Category :": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"Course Status :": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"Course Type :": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"Duration :": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"End Date :": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"Exam Date :": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"Level :": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"Professor": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"Start Date :": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"University": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"description": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"link": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}