在问题的末尾给出了一个终端命令,显示一个简单的Elasticsearch映射。我需要使用Elasticsearch-PHP为索引设置这种映射。我需要在数据索引的时候这样做。
我知道如何在Elasticsearch-PHP中索引。就像
for($i = 0; $i < 100; $i++) {
$params['body'][] = [
'index' => [
'_index' => 'my_index',
'_type' => 'my_type',
]
];
$params['body'][] = [
'my_field' => 'my_value',
'second_field' => 'some more values'
];
}
$responses = $client->bulk($params);我的问题是,我将如何设置一个映射,对应于下面以elasticsearch-PHP格式给出的特定映射(我相信它将成为一个关联数组,但我不确定进一步的细节)。
下面是ES映射示例,我想将其转换为PHP中使用的格式:
PUT _template/packets
{
"template": "packets-*",
"mappings": {
"pcap_file": {
"dynamic": "false",
"properties": {
"timestamp": {
"type": "date"
},
"layers": {
"properties": {
"ip": {
"properties": {
"ip_ip_src": {
"type": "ip"
},
"ip_ip_dst": {
"type": "ip"
}
}
}
}
}
}
}
}
}发布于 2017-10-20 10:41:03
如果您不更新您的映射-您不必每次将数据重新索引到elasticsearch时都要进行put映射。但是,如果您这样做了,您可以使用新名称创建索引,可以这样做:
$put = [
'mappings' => [
// your mapping here
],
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://yourHost:9200/yourIndex');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($put));
curl_exec($ch);或者您可以使用elasticsearch包:
$params = [
'index' => 'yourIndex',
'body' => [
'mappings' => [
// your mapping here
]
]
];
$response = $client->indices()->create($params);https://stackoverflow.com/questions/46846773
复制相似问题