• Stars
    star
    5,190
  • Rank 7,983 (Top 0.2 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Official PHP client for Elasticsearch.

Elasticsearch PHP client

Build status Latest Stable Version Total Downloads

This is the official PHP client for Elasticsearch.

Download the latest version of Elasticsearch or sign-up for a free trial of Elastic Cloud.

Contents


Installation

Refer to the Installation section of the getting started documentation.

Connecting

Refer to the Connecting section of the getting started documentation.

Usage

The elasticsearch-php client offers 400+ endpoints for interacting with Elasticsearch. A list of all these endpoints is available in the official documentation of Elasticsearch APIs.

Here we reported the basic operation that you can perform with the client: index, search and delete.

Versioning

This client is versioned and released alongside Elasticsearch server.

To guarantee compatibility, use the most recent version of this library within the major version of the corresponding Enterprise Search implementation.

For example, for Elasticsearch 7.16, use 7.16 of this library or above, but not 8.0.

Compatibility

The Elasticsearch client is compatible with currently maintained PHP versions.

Language clients are forward compatible; meaning that clients support communicating with greater or equal minor versions of Elasticsearch without breaking. It does not mean that the client automatically supports new features of newer Elasticsearch versions; it is only possible after a release of a new client version. For example, a 8.12 client version won't automatically support the new features of the 8.13 version of Elasticsearch, the 8.13 client version is required for that. Elasticsearch language clients are only backwards compatible with default distributions and without guarantees made.

Elasticsearch Version Elasticsearch-PHP Branch Supported
main main
8.x 8.x 8.x
7.x 7.x 7.17

Backward Incompatible Changes 💥

The 8.0.0 version of elasticsearch-php contains a new implementation compared with 7.x. It supports PSR-7 for HTTP messages and PSR-18 for HTTP client communications.

We tried to reduce the BC breaks as much as possible with 7.x but there are some (big) differences:

  • we changed the namespace, now everything is under Elastic\Elasticsearch
  • we used the elastic-transport-php library for HTTP communications;
  • we changed the Exception model, using the namespace Elastic\Elasticsearch\Exception. All the exceptions extends the ElasticsearchException interface, as in 7.x
  • we changed the response type of each endpoints using an Elasticsearch response class. This class wraps a a PSR-7 response allowing the access of the body response as array or object. This means you can access the API response as in 7.x, no BC break here! 👼
  • we changed the ConnectionPool in NodePool. The connection naming was ambigous since the objects are nodes (hosts)

You can have a look at the BREAKING_CHANGES file for more information.

Mock the Elasticsearch client

If you need to mock the Elasticsearch client you just need to mock a PSR-18 HTTP Client.

For instance, you can use the php-http/mock-client as follows:

use Elastic\Elasticsearch\ClientBuilder;
use Elastic\Elasticsearch\Response\Elasticsearch;
use Http\Mock\Client;
use Nyholm\Psr7\Response;

$mock = new Client(); // This is the mock client

$client = ClientBuilder::create()
    ->setHttpClient($mock)
    ->build();

// This is a PSR-7 response
$response = new Response(
    200, 
    [Elasticsearch::HEADER_CHECK => Elasticsearch::PRODUCT_NAME],
    'This is the body!'
);
$mock->addResponse($response);

$result = $client->info(); // Just calling an Elasticsearch endpoint

echo $result->asString(); // This is the body!

We are using the ClientBuilder::setHttpClient() to set the mock client. You can specify the response that you want to have using the addResponse($response) function. As you can see the $response is a PSR-7 response object. In this example we used the Nyholm\Psr7\Response object from the nyholm/psr7 project. If you are using PHPUnit you can even mock the ResponseInterface as follows:

$response = $this->createMock('Psr\Http\Message\ResponseInterface');

Notice: we added a special header in the HTTP response. This is the product check header, and it is required for guarantee that elasticsearch-php is communicating with an Elasticsearch server 8.0+.

For more information you can read the Mock client section of PHP-HTTP documentation.

FAQ 🔮

Where do I report issues with the client?

If something is not working as expected, please open an issue.

Where else can I go to get help?

You can checkout the Elastic community discuss forums.

Contribute 🚀

We welcome contributors to the project. Before you begin, some useful info...

  • If you want to contribute to this project you need to subscribe to a Contributor Agreement.
  • Before opening a pull request, please create an issue to discuss the scope of your proposal.
  • If you want to send a PR for version 8.0 please use the 8.0 branch, for 8.1 use the 8.1 branch and so on.
  • Never send PR to master unless you want to contribute to the development version of the client (master represents the next major version).
  • Each PR should include a unit test using PHPUnit. If you are not familiar with PHPUnit you can have a look at the reference.

Thanks in advance for your contribution! ❤️

License 📗

MIT © Elastic

More Repositories

1

elasticsearch

Free and Open, Distributed, RESTful Search Engine
Java
65,029
star
2

kibana

Your window into the Elastic Stack
TypeScript
19,520
star
3

logstash

Logstash - transport and process your logs, events, or other data
Java
13,615
star
4

elasticsearch-js

Official Elasticsearch client library for Node.js
TypeScript
5,174
star
5

go-elasticsearch

The official Go client for Elasticsearch
Go
4,933
star
6

elasticsearch-py

Official Python client for Elasticsearch
Python
4,034
star
7

elasticsearch-dsl-py

High level Python client for Elasticsearch
Python
3,695
star
8

elasticsearch-definitive-guide

The Definitive Guide to Elasticsearch
HTML
3,521
star
9

elasticsearch-net

This strongly-typed, client library enables working with Elasticsearch. It is the official client maintained and supported by Elastic.
C#
3,469
star
10

curator

Curator: Tending your Elasticsearch indices
Python
3,032
star
11

elasticsearch-rails

Elasticsearch integrations for ActiveModel/Record and Ruby on Rails
Ruby
3,017
star
12

examples

Home for Elasticsearch examples available to everyone. It's a great way to get started.
Jupyter Notebook
2,587
star
13

cloud-on-k8s

Elastic Cloud on Kubernetes
Go
2,574
star
14

elasticsearch-ruby

Ruby integrations for Elasticsearch
Ruby
1,928
star
15

elasticsearch-hadoop

🐘 Elasticsearch real-time search and analytics natively integrated with Hadoop
Java
1,915
star
16

detection-rules

Python
1,884
star
17

helm-charts

You know, for Kubernetes
Python
1,807
star
18

search-ui

Search UI. Libraries for the fast development of modern, engaging search experiences.
TypeScript
1,796
star
19

logstash-forwarder

An experiment to cut logs in preparation for processing elsewhere. Replaced by Filebeat: https://github.com/elastic/beats/tree/master/filebeat
Go
1,788
star
20

ansible-elasticsearch

Ansible playbook for Elasticsearch
Ruby
1,567
star
21

stack-docker

Project no longer maintained.
Shell
1,189
star
22

apm-server

APM Server
Go
1,100
star
23

protections-artifacts

Elastic Security detection content for Endpoint
YARA
980
star
24

ecs

Elastic Common Schema
Python
920
star
25

ember

Elastic Malware Benchmark for Empowering Researchers
Jupyter Notebook
799
star
26

elasticsearch-docker

Official Elasticsearch Docker image
Python
790
star
27

elasticsearch-rs

Official Elasticsearch Rust Client
Rust
612
star
28

elasticsearch-labs

Notebooks & Example Apps for Search & AI Applications with Elasticsearch
Jupyter Notebook
597
star
29

elasticsearch-cloud-aws

AWS Cloud Plugin for Elasticsearch
580
star
30

apm-agent-nodejs

Elastic APM Node.js Agent
JavaScript
540
star
31

apm-agent-dotnet

Elastic APM .NET Agent
C#
540
star
32

apm-agent-java

Elastic APM Java Agent
Java
536
star
33

eland

Python Client and Toolkit for DataFrames, Big Data, Machine Learning and ETL in Elasticsearch
Python
516
star
34

elasticsearch-mapper-attachments

Mapper Attachments Type plugin for Elasticsearch
Java
503
star
35

elasticsearch-servicewrapper

A service wrapper on top of elasticsearch
Shell
489
star
36

apm-agent-go

Official Go agent for Elastic APM
Go
390
star
37

sense

A JSON aware developer's interface to Elasticsearch. Comes with handy machinery such as syntax highlighting, autocomplete, formatting and code folding.
JavaScript
382
star
38

apm-agent-python

Official Python agent for Elastic APM
Python
381
star
39

elastic-charts

TypeScript
365
star
40

stream2es

Stream data into ES (Wikipedia, Twitter, stdin, or other ESes)
Clojure
356
star
41

timelion

Timelion was absorbed into Kibana 5. Don't use this. Time series composer for Elasticsearch and beyond.
JavaScript
347
star
42

apm

Elastic Application Performance Monitoring - resources and general issue tracking for Elastic APM.
Gherkin
317
star
43

elasticsearch-net-example

A tutorial repository for Elasticsearch and NEST
305
star
44

elasticsearch-migration

This plugin will help you to check whether you can upgrade directly to the next major version of Elasticsearch, or whether you need to make changes to your data and cluster before doing so.
291
star
45

logstash-docker

Official Logstash Docker image
Python
286
star
46

elasticsearch-py-async

Backend for elasticsearch-py based on python's asyncio module.
Python
283
star
47

support-diagnostics

Support diagnostics utility for elasticsearch and logstash
Java
278
star
48

elasticsearch-java

Official Elasticsearch Java Client
Java
274
star
49

es2unix

Command-line ES
Clojure
274
star
50

elasticsearch-analysis-smartcn

Smart Chinese Analysis Plugin for Elasticsearch
268
star
51

dockerfiles

Dockerfiles for the official Elastic Stack images
Shell
253
star
52

go-sysinfo

go-sysinfo is a library for collecting system information.
Go
249
star
53

kibana-docker

Official Kibana Docker image
Python
243
star
54

elasticsearch-metrics-reporter-java

Metrics reporter, which reports to elasticsearch
Java
232
star
55

apm-agent-php

Elastic APM PHP Agent
PHP
229
star
56

docs

Ruby
229
star
57

elasticsearch-river-twitter

Twitter River Plugin for elasticsearch (STOPPED)
Java
202
star
58

elasticsearch-formal-models

Formal models of core Elasticsearch algorithms
Isabelle
200
star
59

rally-tracks

Track specifications for the Elasticsearch benchmarking tool Rally
Python
197
star
60

integrations

Elastic Integrations
Handlebars
194
star
61

beats-dashboards

DEPRECATED. Moved to https://github.com/elastic/beats. Please use the new repository to add new issues.
Shell
192
star
62

elasticsearch-analysis-icu

ICU Analysis plugin for Elasticsearch
189
star
63

elasticsearch-river-rabbitmq

RabbitMQ River Plugin for elasticsearch (STOPPED)
Java
173
star
64

terraform-provider-ec

Go
171
star
65

elasticsearch-analysis-kuromoji

Japanese (kuromoji) Analysis Plugin
168
star
66

dorothy

Dorothy is a tool to test security monitoring and detection for Okta environments
Python
167
star
67

beats-docker

Official Beats Docker images
Python
165
star
68

elasticsearch-river-couchdb

CouchDB River Plugin for elasticsearch (STOPPED)
Java
163
star
69

SWAT

Simple Workspace Attack Tool (SWAT) is a tool for simulating malicious behavior against Google Workspace in reference to the MITRE ATT&CK framework.
Python
156
star
70

apm-agent-ruby

Elastic APM agent for Ruby
Ruby
156
star
71

go-freelru

GC-less, fast and generic LRU hashmap library for Go
Go
151
star
72

require-in-the-middle

Module to hook into the Node.js require function
JavaScript
149
star
73

harp

Secret management by contract toolchain
Go
145
star
74

go-libaudit

go-libaudit is a library for communicating with the Linux Audit Framework.
Go
142
star
75

ml-cpp

Machine learning C++ code
C++
139
star
76

ecs-logging-java

Centralized logging for Java applications with the Elastic stack made easy
Java
137
star
77

ansible-beats

Ansible Beats Role
Ruby
131
star
78

logstash-contrib

THIS REPOSITORY IS NO LONGER USED.
Ruby
128
star
79

elasticsearch-analysis-phonetic

Phonetic Analysis Plugin for Elasticsearch
127
star
80

azure-marketplace

Elasticsearch Azure Marketplace offering + ARM template
Shell
122
star
81

golang-crossbuild

Shell
121
star
82

elastic-agent

Elastic Agent - single, unified way to add monitoring for logs, metrics, and other types of data to a host.
Go
121
star
83

anonymize-it

a general utility for anonymizing data
Python
117
star
84

bpfcov

Source-code based coverage for eBPF programs actually running in the Linux kernel
C
115
star
85

windows-installers

Windows installers for the Elastic stack
C#
113
star
86

terraform-provider-elasticstack

Terraform provider for Elastic Stack
Go
111
star
87

makelogs

JavaScript
108
star
88

elasticsearch-lang-python

Python language Plugin for elasticsearch
104
star
89

stack-docs

Elastic Stack Documentation
Java
96
star
90

sysgrok

LLM-driven assistant for analyzing, understanding and optimizing systems
Python
94
star
91

elasticsearch-lang-javascript

JavaScript language Plugin for elasticsearch
93
star
92

crawler

Ruby
92
star
93

elasticsearch-specification

Elasticsearch full specification
TypeScript
89
star
94

elasticsearch-perl

Official Perl low-level client for Elasticsearch.
Perl
87
star
95

next-eui-starter

Start building Kibana protoypes quickly with the Next.js EUI Starter
TypeScript
87
star
96

vue-search-ui-demo

A demo of implementing Elastic's Search UI and App Search using Vue.js
Vue
87
star
97

elasticsearch-transport-thrift

Thrift Transport for elasticsearch (STOPPED)
Java
84
star
98

beats

🐠 Beats - Lightweight shippers for Elasticsearch & Logstash
Go
83
star
99

ecs-dotnet

.NET integrations that use the Elastic Common Schema (ECS)
HTML
82
star
100

generator-kibana-plugin

DEPRECATED Yeoman Generator for Kibana Plugins, please use https://github.com/elastic/template-kibana-plugin/
JavaScript
79
star