当我在 ElasticSearch 中创建索引并尝试使用 percolate 时,出现错误,即索引中不存在 percolate 类型的字段。但是当我在索引中观看时,字段存在。
我将向您展示映射,文档在索引、错误和查询中的样子。
请帮我!我真的在尽我所能在谷歌上找到的东西。也许有人知道是什么问题。
索引映射:
'index' => 'stop-words',
'body' => [
'settings' => [
'number_of_shards' => 3,
'number_of_replicas' => 2,
'analysis' => [
'analyzer' => [
'simple_punctuation_analyzer' => [
'type' => 'custom',
'tokenizer' => 'simple_punctuation_tokenizer',
'char_filter' => ['html_strip'],
'filter' => ['lowercase']
]
],
'tokenizer' => [
'simple_punctuation_tokenizer' => [
'type' => 'char_group',
'tokenize_on_chars' => [
'whitespace',
',',
'.',
'\'',
'"',
':',
';',
'?',
'!'
]
]
]
]
],
'mappings' => [
'properties' => [
'id' => [
'type' => 'long'
],
'stop_word' => [
'type' => 'text',
'analyzer' => 'simple_punctuation_analyzer',
'fields' => [
'keyword' => [
'type' => 'keyword'
]
]
],
'stop_query' => [
'type' => 'percolator'
],
'status' => [
'type' => 'boolean'
],
]
]
]
];
索引中的文档:
{
"_index": "stop-words",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"id": 1,
"stop_word": "asdasdasd",
"stop_query": {
"match_phrase": {
"stop_word": {
"query": "asdasdasd",
"analyzer": "simple_punctuation_analyzer"
}
}
}
}
},
错误:
Error: {"error":{"root_cause":
[{"type":"query_shard_exception",
"reason":"field [stop_query] does not exist",
"index_uuid":"I9ZjvdjCQuyHylKTDicRRg",
"index":"stop-words"}],
"type":"search_phase_execution_exception",
"reason":"all shards failed",
"phase":"query",
"grouped":true,
"failed_shards":[{"shard":0,"index":"stop-words",
"node":"PqSzl30DRnaNkFyp8RkOxg",
"reason":
{"type":"query_shard_exception",
"reason":"field [stop_query] does not exist",
"index_uuid":"I9ZjvdjCQuyHylKTDicRRg",
"index":"stop-words"}}]},"status":400}
我的查询:
'index' => StopWord::STOP_WORDS_ELASTICSEARCH_INDEX_NAME,
'_source' => ['id'],
'body' => [
'query' => [
'bool' => [
'filter' => [
['term' => ['status' => true]],
['percolate' => [
'field' => 'stop_query',
'documents' => $fields
]]
]
]
]
]