я использую Elasticsearch-PHP [6.0]
У меня есть индекс products
где у меня есть названия продуктов, которые используют фразу-предложение.
Настройка индекса
{
"products": {
"aliases": {},
"mappings": {
"surat": {
"properties": {
"suggest": {
"type": "completion",
"analyzer": "simple",
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50
},
"title": {
"type": "text",
"fields": {
"reverse": {
"type": "text",
"analyzer": "reverse"},
"trigram": {
"type": "text",
"analyzer": "trigram"}
}
}
}
}
},
"settings": {
"index": {
"number_of_shards": "5",
"provided_name": "products",
"creation_date": "1525244538694",
"analysis": {
"filter": {
"shingle": {
"max_shingle_size": "3",
"min_shingle_size": "2",
"type": "shingle"}
},
"analyzer": {
"reverse": {
"filter": [
"standard",
"reverse"],
"type": "custom",
"tokenizer": "standard"},
"trigram": {
"filter": [
"standard",
"shingle"],
"type": "custom",
"tokenizer": "standard"}
}
},
"number_of_replicas": "1",
"uuid": "ljVUaIOURjqFOyQ0CXZmow",
"version": {
"created": "6020499"}
}
}
}
}
Параметры запроса
$params = [
'index' => 'products',
'body' => [
"text" => fortune,
"simple_phrase" => [
"phrase" => [
"field" => "title.trigram",
"size" => 1,
"direct_generator" => [
[
"field" => "title.trigram",
"suggest_mode" => "always"],
[
"field" => "title.reverse",
"suggest_mode" => "always",
"pre_filter" => "reverse",
"post_filter" => "reverse"]
]
]
]
]
];
$response = $client->search($params);
ошибка
{"error":{"root_cause":[{"type":"parsing_exception","reason":"Unknown key for a VALUE_STRING in [text].","line":1,"col":9}],"type":"parsing_exception","reason":"Unknown key for a VALUE_STRING in [text].","line":1,"col":9},"status":400}
Спасибо за вашу помощь.
Вы просто скучаете по suggest
ключевое слово:
$params = [
'index' => 'products',
'body' => [
"suggest" => [ <-- add this
"text" => fortune,
"simple_phrase" => [
"phrase" => [
"field" => "title.trigram",
"size" => 1,
"direct_generator" => [
[
"field" => "title.trigram",
"suggest_mode" => "always"],
[
"field" => "title.reverse",
"suggest_mode" => "always",
"pre_filter" => "reverse",
"post_filter" => "reverse"]
]
]
]
] <-- and this
]
];
$response = $client->search($params);
Других решений пока нет …