In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to apply elasticsearch to PHP, I believe many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
1. Environmental requirements: PHP_VERSION > = 5.3.9 dint composer tool
two。 Create a new folder on disk E named elastic, copy composer.phar to the E:/elastic directory
3. Open a command line window and enter E:/elastic
4. Run on the command line: phpcomposer.pharrequireelasticsearch/elasticsearch
5. A vendor directory will appear under the E:/elastic directory and the installation will be successful
6. How to use: require'vendor/autoload.php';$client=newElasticsearch\ Client ()
Create an index
Include ('. / vendor/autoload.php'); $elastic=newElasticsearch\ Client (); $index ['index'] =' log';// index name $index ['type'] =' ems_run_log';// type name $data ['body'] [' settings'] ['number_of_shards'] = 5 data / number of main shards $data [' body'] ['settings'] [' number_of_replicas'] = 0 Landscape / number of slave shards $elastic- > indices ()-> create ($index)
Insert index data
Include ('. / vendor/autoload.php'); $elastic=newElasticsearch\ Client (); $index ['index'] =' log';// index name $index ['type'] =' ems_run_log';// type name $index ['id'] = 1 id / no id, the system will automatically generate a unique id$index [' body'] = array ('mac'= >' fcd5d900beca','customer_id'= > 3 theatrical products = > 5 cinematic products = > 2); $elastic- > index ($index)
Query
Include ('. / vendor/autoload.php'); $elastic=newElasticsearch\ Client (); $index ['index'] =' log';// index name $index ['type'] =' ems_run_log';// type name $index ['body'] [' query'] ['match'] [' mac'] = 'fcd5d900beca';$index [' size'] = 10 leading index ['from'] = 200 leading index Elastic-> search ($index)
Delete document
Include ('. / vendor/autoload.php'); $elastic=newElasticsearch\ Client (); $index ['index'] =' test';// index name $index ['type'] =' ems_test';// type name $index ['id'] = 2 ems_test';// Elastic-> delete ($index)
After reading the above, have you mastered how elasticsearch is used in PHP? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.