PHP Classes

PHP Elastic Search for MySQL: Index and search MySQL records with Elastic Search

Recommend this page to a friend!
  Info   View files Example   View files View files (22)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 58%Total: 557 All time: 5,453 This week: 177Up
Version License PHP version Categories
mysqlwithelasticsear 8Custom (specified...5.6PHP 5, Databases, Searching
Description 

Author

This class can index and search MySQL records with Elastic Search.

It takes configuration of MySQL table fields and queries that the class uses to retrieve the data from the database to index with Elastic Search.

The class takes a connection object of the MySQLi class and inserts the data to index.

It can also perform searches for given keywords and returns the matching records that were previously indexed.

Innovation Award
PHP Programming Innovation award nominee
February 2017
Number 11


Prize: One copy of the Zend Studio
MySQL has a good full text search engine built-in but when you try to use full text searches and at the same time have the application updating the database, it may be very slow because updating the indexes slow down the rest of the database accesses.

It is often faster to index the data to be searched with a separate database.

Elastic search is an independent engine for indexing and searching data using a REST API.

This class can index and search MySQL records using Elastic Search. This way you can provide a full text search on data in a MySQL database without overloading the main MySQL server.

Manuel Lemos
Picture of Ahmed Khan
Name: Ahmed Khan <contact>
Classes: 9 packages by
Country: Pakistan Pakistan
Age: ???
All time rank: 245134 in Pakistan Pakistan
Week rank: 568 Up9 in Pakistan Pakistan Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php
require "vendor/autoload.php";

use
SyncMySql\SyncMySQL;
use
SyncMySql\Connection\MySQLiConnection;
use
SearchElastic\Search;
use
ElasticSearchClient\Mapping;

// $con = new mysqli('localhost','root','','laravel');

// $mysqls = new MySQLiConnection();
$connection = new \PDO('mysql:host=localhost;dbname=laravel;','root', '');
$sync = new Search();
$sync->setIndex("blog");
$sync->setType("user");
$sync->setSearchColumn("name");
// $sync->setConnection($mysqls);
echo print_r($sync->search("ahmed khan"));
// echo print_r($sync->updateNode($con,'users',21));
// echo $sync->insertNode([
// "id" => 5,
// "name0" => "abc",
// "design" => "pattern"
// ]);
  
// $search = new Search();
// $search->setIndex("abc");
// $search->setType("asd");
// $search->setSearchColumn("name");
// echo print_r($search->search("ahmed"));

// $client = new Mapping();
// // $map=;
// $mapping = ['index' => 'abc3',
// 'body' => [
// 'mappings' => [
// 'article' => [
// 'properties' => [
// 'id' => [
// 'type' => 'integer'
// ],
// 'article_name' => [
// 'type' => 'string'
// ],
// 'article_content' => [
// 'type' => 'string'
// ],
// 'article_url' => [
// 'type' => 'string'
// ],
// 'category_name' => [
// 'type' => 'string'
// ],
// 'username' => [
// 'type' => 'string'
// ],
// 'date' => [
// 'type' => 'date',
// 'format' => 'dd-MM-yyyy'
// ],
// 'article_img' => [
// 'type' => 'string'
// ],
// ]
// ]
// ]
// ]
// ];
// echo print_r($client->deleteMapping("abc"));

$connection = new PDO('mysql:host=localhost;dbname=laravel;','root', '');

print_r($connection);


  Files folder image Files  
File Role Description
Files folder imagesrc (4 directories)
Files folder imagetests (4 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageElasticSearchClient (2 files)
Files folder imageMySQLWithElasticsearchExceptions (2 files)
Files folder imageSearchElastic (1 file, 1 directory)
Files folder imageSyncMySql (2 files, 1 directory)

  Files folder image Files  /  src  /  ElasticSearchClient  
File Role Description
  Plain text file ElasticSearchClient.php Class Class source
  Plain text file Mapping.php Class Class source

  Files folder image Files  /  src  /  MySQLWithElasticsearchExceptions  
File Role Description
  Plain text file SearchException.php Class Class source
  Plain text file SyncMySqlExceptions.php Class Class source

  Files folder image Files  /  src  /  SearchElastic  
File Role Description
Files folder imageSearchAbstract (1 file)
  Plain text file Search.php Class Class source

  Files folder image Files  /  src  /  SearchElastic  /  SearchAbstract  
File Role Description
  Plain text file SearchAbstract.php Class Class source

  Files folder image Files  /  src  /  SyncMySql  
File Role Description
Files folder imageConnection (4 files)
  Plain text file SyncMySql.php Class Class source
  Plain text file SyncMySqlYii.php Class Class source

  Files folder image Files  /  src  /  SyncMySql  /  Connection  
File Role Description
  Plain text file Connection.php Class Class source
  Plain text file MySQLiConnection.php Class Class source
  Plain text file PDOConnection.php Class Class source
  Plain text file YiiConnection.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file ElasticSearchClientTest.php Class Class source
  Plain text file MappingTest.php Class Class source
  Plain text file SearchTest.php Class Class source
  Plain text file SyncMySqlTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:557
This week:0
All time:5,453
This week:177Up
 User Ratings  
 
 All time
Utility:75%StarStarStarStar
Consistency:75%StarStarStarStar
Documentation:66%StarStarStarStar
Examples:66%StarStarStarStar
Tests:-
Videos:-
Overall:58%StarStarStar
Rank:1570