【发布时间】:2016-04-24 12:45:59
【问题描述】:
如果我应该根据逗号分隔的字段搜索逗号分隔的字符串,因此我在映射中执行以下操作,但显示 MapperParsingException[Analyzer [comma] not found for field [conduct_days]] 错误。
$course = new Course();
$course->no = '1231321';
.......
.......
$course->save();
// Now index the new created course
$client = \Elasticsearch\ClientBuilder::create()->build();
$params = [
'index' => 'my_index',
'type' => 'my_resources',
'body' => [
'my_resources' => [
'_source' => [
'enabled' => true
],
'settings' => [
"analysis" => [
"tokenizer" => [
"comma" => [
"type" => "pattern",
"pattern" => ","
]
],
"analyzer" => [
"comma" => [
"type" => "custom",
"tokenizer" => "comma"
]
]
]
],
'properties' => [
'conduct_days' => array(
'type' => 'string',
'analyzer' => 'comma'
),
'no' => array(
'type' => 'string',
'analyzer' => 'standard'
),
'created_at' => array(
'type' => 'date_time',
"format"=>"YYYY-MM-dd HH:mm:ss||MM/dd/yyyy||yyyy/MM/dd"
),
'updated_at' => array(
'type' => 'date_time',
"format" => "YYYY-MM-dd HH:mm:ss||MM/dd/yyyy||yyyy/MM/dd"
),
'deleted_at' => array(
'type' => 'date_time',
"format" => "YYYY-MM-dd HH:mm:ss||MM/dd/yyyy||yyyy/MM/dd"
),
'created_by' => array(
'type' => 'string',
'analyzer' => 'standard'
),
'updated_by' => array(
'type' => 'string',
'analyzer' => 'standard'
),
'deleted_by' => array(
'type' => 'string',
'analyzer' => 'standard'
)
]
]
]
];
// Update the index mapping
$client->indices()->putMapping($params);
$params = [
'index' => 'promote_kmp',
'type' => 'courses',
'id' => uniqid(),
'body' => [
'id' => $course->id,
'conduct_days' => $course->conduct_days,
'no' => $course->no,
'created_at' => $course->created_at,
'created_by' => $loggedInUser,
]
];
$client->index($params);
假设我必须在具有1,2 和1,2,3 和1,3,5,6 等的行为日字段中搜索1,3,5,7。对于搜索,我想我应该爆炸搜索词,例如如果搜索词是1,2,我应该搜索两次,第一次搜索1,然后搜索2。还有其他搜索解决方案吗?
【问题讨论】:
标签: php search indexing elasticsearch