elasticsearch怎样运用进PHP里

elasticsearch怎样运用进PHP里,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

创新互联公司是一家专业提供威县企业网站建设,专注与网站制作、成都网站建设H5页面制作、小程序制作等业务。10年已为威县众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。

1.环境要求:PHP_VERSION>=5.3.9,composer工具

2.在E盘新建文件夹命名为elastic,,拷贝composer.phar到E:/elastic目录下面

3.打开命令行窗口,进入E:/elastic

4.在命令行运行:phpcomposer.pharrequireelasticsearch/elasticsearch

5.此时E:/elastic目录下会出现一个vendor目录,安装成功

6.使用方法:require'vendor/autoload.php';$client=newElasticsearch\Client();

创建索引

include('./vendor/autoload.php');$elastic=newElasticsearch\Client();$index[‘index’]=‘log’;//索引名称$index[‘type’]=‘ems_run_log’;//类型名称$data[‘body’][‘settings’][‘number_of_shards’]=5;//主分片数量$data[‘body’][‘settings’][‘number_of_replicas’]=0;//从分片数量$elastic->indices()->create($index);

插入索引数据

include('./vendor/autoload.php');$elastic=newElasticsearch\Client();$index[‘index’]=‘log’;//索引名称$index[‘type’]=‘ems_run_log’;//类型名称$index[‘id’]=1//不指定id,系统会自动生成唯一id$index[‘body’]=array(‘mac’=>'fcd5d900beca',‘customer_id’=>3,‘product_id’=>5,‘version’=>2);$elastic->index($index);

查询

include('./vendor/autoload.php');$elastic=newElasticsearch\Client();$index[‘index’]=‘log’;//索引名称$index[‘type’]=‘ems_run_log’;//类型名称$index[‘body’][‘query’][‘match’][‘mac’]=‘fcd5d900beca’;$index[‘size’]=10;$index[‘from’]=200;$elastic->search($index);

删除文档

include('./vendor/autoload.php');$elastic=newElasticsearch\Client();$index['index']='test';//索引名称$index['type']='ems_test';//类型名称$index['id']=2;$elastic->delete($index);

看完上述内容,你们掌握elasticsearch怎样运用进PHP里的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!

名称栏目:elasticsearch怎样运用进PHP里
转载注明:https://www.cdcxhl.com/article10/jcjjgo.html

成都网站建设公司_创新互联,为您提供关键词优化App设计网站制作定制网站服务器托管域名注册

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

h5响应式网站建设