繁体   English   中英

如何在Elasticsearch-PHP中设置此简单的Elasticsearch映射?

[英]how to setup this simple Elasticsearch Mapping in Elasticsearch-PHP?

问题末尾给出了一个终端命令,该命令显示了一个简单的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"
                }
              }
            }
          }
        }
      }
    }
  }
}

如果您不更新映射-则不必在每次put数据重新索引到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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM