Giter VIP home page Giter VIP logo

elasticsearch-query-builder's Introduction

ElasticSearch Query Builder

img php

This is a PHP library which helps you build query for an ElasticSearch client by using a fluent interface.

WARNING: This branch contains the next 3.x release. Check the corresponding issue for the roadmap.

Installation

composer require erichard/elasticsearch-query-builder "^3.0@beta"

Usage

use Erichard\ElasticQueryBuilder\QueryBuilder;
use Erichard\ElasticQueryBuilder\Aggregation\Aggregation;
use Erichard\ElasticQueryBuilder\Filter\Filter;

$qb = new QueryBuilder();

$qb
    ->setIndex('app')
    ->setSize(10)
;

// Add an aggregation
$qb->addAggregation(Aggregation::terms('agg_name', 'my_field'));
$qb->addAggregation(Aggregation::terms('agg_name_same_as_field'));

// Set query
$qb->setQuery(Query::terms('field', 'value'));

// I am using a client from elasticsearch/elasticsearch here
$results = $client->search($qb->build());

with PHP 8.1 you can use named arguments like this:

$query = new BoolQuery(must: [
    new RangeQuery(
        field: 'price',
        gte: 100
    ),
    new RangeQuery(
        field: 'stock',
        gte: 10
    ),
]);

or with the factory

$query = Query::bool(must: [
    Query::range(
        field: 'price',
        gte: 100
    ),
    Query::range(
        field: 'stock',
        gte: 10
    ),
]);

Contribution

  • Use PHPCS fixer and PHPStan
    • composer lint
  • Update tests (PHPUnit)
    • composer test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.