PHPackages                             alirzaj/laravel-elasticsearch-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. alirzaj/laravel-elasticsearch-builder

ActiveLibrary[Database &amp; ORM](/categories/database)

alirzaj/laravel-elasticsearch-builder
=====================================

a query builder for elasticsearch database

V5.0.0(8mo ago)27.9k2MITPHPPHP ^8.1|^8.2

Since Nov 4Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/alirzaj/laravel-elasticsearch-builder)[ Packagist](https://packagist.org/packages/alirzaj/laravel-elasticsearch-builder)[ Docs](https://github.com/alirzaj/laravel-elasticsearch-builder)[ GitHub Sponsors](https://github.com/:vendor_name)[ RSS](/packages/alirzaj-laravel-elasticsearch-builder/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (9)Versions (35)Used By (0)

a query builder for elasticsearch database
==========================================

[](#a-query-builder-for-elasticsearch-database)

[![Latest Version on Packagist](https://camo.githubusercontent.com/50867395203f9c65d5ca12227dd727bcfeda6bdcc8434b0912328a50d7709586/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c69727a616a2f6c61726176656c2d656c61737469637365617263682d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alirzaj/laravel-elasticsearch-builder)[![Total Downloads](https://camo.githubusercontent.com/1c112a24d5330658f45656c64502079d37196e2e28dcae3138e84bb25542aa3d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c69727a616a2f6c61726176656c2d656c61737469637365617263682d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alirzaj/laravel-elasticsearch-builder)

---

This package can build queries for elasticsearch database and provides an easy way to add Eloquent models to an elasticsearch index.

It is not trying to provide Eloquent-like api to work with elasticsearch. instead, it will give you methods that are much like writing a query in elasticsearch but in a more object-oriented and nicer way.

this package contains the queries that I needed on my projects. so if you feel the need of a method or feature please open an issue, and I will try to implement it as soon as possible.

- [a query builder for elasticsearch database](#a-query-builder-for-elasticsearch-database)
- [Installation](#installation-)
    - [Usage](#usage)
- [define indices](#define-indices)
- [create indices](#create-indices)
- [delete indices](#delete-indices)
- [configuration](#configuration)
- [making models searchable](#making-models-searchable)
- [indexing documents without eloquent models and using searchable trait](#indexing-documents-without-eloquent-models-and-using-searchable-trait)
- [bulk indexing documents](#bulk-indexing-documents)
- [update documents having a condition](#update-documents-having-a-condition)
- [add an item to a nested field](#add-an-item-to-a-nested-field)
- [add an item to an array field](#add-an-item-to-an-array-field)
- [update a document's nested field items having a condition](#update-a-documents-nested-field-items-having-a-condition)
- [update all documents' nested field items having a condition](#update-all-documents-nested-field-items-having-a-condition)
- [remove item from a nested field in a specific document](#remove-item-from-a-nested-field-in-a-specific-document)
- [remove item from a nested field by conditions](#remove-item-from-a-nested-field-by-conditions)
- [delete a document](#delete-a-document)
- [delete all documents that meet some conditions](#delete-all-documents-that-meet-some-conditions)
- [querying indices](#querying-indices)
- [include an index in query:](#include-an-index-in-query)
- [boost the score of some indices](#boost-the-score-of-some-indices)
- [determine search type](#determine-search-type)
- [find a document by its id](#find-a-document-by-its-id)
- [match](#match-)
- [match\_all](#matchall)
- [multi\_match](#multimatch)
- [nested](#nested)
- [exists](#exists)
- [bool](#bool)
- [term](#term)
- [terms](#terms)
- [range](#range)
- [dis\_max](#dismax)
- [aggregations (aggs)](#aggregations-aggs)
- [working with array fields](#working-with-array-fields)
- [getting results](#getting-results)
- [determine a size limit for results](#determine-a-size-limit-for-results)
- [determine from option for getting results (pagination)](#determine-from-option-for-getting-results-pagination)
- [select specific fields](#select-specific-fields)
- [build queries based on conditions](#build-queries-based-on-conditions)
- [debugging](#debugging)
- [using the low-level elasticsearch client](#using-the-low-level-elasticsearch-client)
- [logging](#logging)
- [Testing Helpers](#testing-helpers)
    - [refreshing indices state](#refreshing-indices-state)
    - [assertions](#assertions)
- [Credits](#credits)
- [License](#license)

Installation
============

[](#installation)

to install this package, require it via composer:

`composer require alirzaj/laravel-elasticsearch-builder`

Usage
-----

[](#usage)

define indices
==============

[](#define-indices)

first you need to define index classes. an index class must extend the **Alirzaj\\ElasticsearchBuilder\\Index** class. here is an example:

```
