Elasticsearch PHP:[text] 中 VALUE_STRING 的未知键
Elasticsearch PHP: Unknown key for a VALUE_STRING in [text]
我正在使用 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);
我正在使用 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);