index.php api,分布式搜索引擎elasticsearch PHP API index mapping操作

require '../vendor/autoload.php';

function p ($param) {

if (!is_array($param) && !is_object($param))

{

echo $param;

return true;

}

echo '

';

print_r($param);

echo '

';

}

$client = new Elasticsearch\Client();

//mapping操作

//为index_002mapping

$indexParam['index'] = 'index_002';

$indexParam['type'] = 'type_001';

$mapParam = array(

'_source' => array(

'enable' => true,

),

'properties' => array(

'title' => array(

'type' => 'string',//field_name_1值为string类型

'analyzer' => 'standard'//分析

),

'score' => array(

'type' => 'float',//分数为float

'index' => 'not_analyzed'

),

'url' => array(

'type' => 'string',

'no-index'=>'not_analyzed'//不进行索引,默认就是不索引

)

),

);

//index为db,type为table

//mapp就相当与给table分配字段以及属性

// $indexParam['body'][$indexParam['type']] = $mapParam;

// $ret = $client -> indices() -> putMapping($indexParam);

// p($ret);

//Array

// (

// [acknowledged] => 1

// )

//查看刚才创建的mapping

$ret = $client -> indices() -> getMapping($indexParam);

p($ret);

//打印结果

// Array

// (

// [index_002] => Array

// (

// [mappings] => Array

// (

// [type_001] => Array

// (

// [properties] => Array

// (

// [score] => Array

// (

// [type] => float

// )

// [title] => Array

// (

// [type] => string

// [analyzer] => standard

// )

// [url] => Array

// (

// [type] => string

// )

// )

// )

// )

// )

// )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值