Download the PHP package etsetra/elasticsearch without Composer

On this page you can find all versions of the php package etsetra/elasticsearch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package elasticsearch

Elasticsearch

Installation

composer require etsetra/elasticsearch
  1. Create config file

    $ php artisan vendor:publish --tag="etsetra-elasticsearch-config"

  2. Update .env file

    ELASTICSEARCH_SERVERS=127.0.0.1:9200,127.0.0.1:9201,127.0.0.1:9202

    ELASTICSEARCH_RETRIES=2

    ELASTICSEARCH_PASSWORD=1234 //This password is unique to you. Used to delete index

    ELASTICSEARCH_PREFIX=app //prefix of indexes

Model & Migration

$ php artisan elasticsearch:model MyModel

// Model created successfully.

or with migration

$ php artisan elasticsearch:model MyModel --m

// Model created successfully.

// Created Migration: 2021_09_25_151308_create_my_model_table

$ php artisan migrate

You can enter standard elasticsearch mapping parameters into the created migration file.

Delete Index

$ php artisan elasticsearch:index:delete

resim

The password is the ELASTICSEARCH_PASSWORD value in the env file.

Put Mapping

use App\Models\MyModel;

(new MyModel)->putIndexMapping(
    [
        'new_column_name' => [
            'type' => 'keyword'
        ]
    ]
);

Search Document

use App\Models\MyModel;

$data = (new MyModel)->find(
    [
        'bool' => [
            'filter' => [
                'terms' => [
                    'user_id' => [ 1 ]
                ]
            ]
        ]
    ],
    [
        'from' => 0,
        'size' => 10,
        'sort' => [
            [
                'created_at' => [
                    'order' => 'desc'
                ]
            ]
        ]
    ]
);

// You can use all parameters of Elasticsearch.

// Results
stdClass Object
(
    [success] => ok
    [source] => Array
        (
            [0] => Array
                (
                    [id] => J6SzTtlUFpTQ
                    [user_id] => 1
                    [description] => 3 - Dolor egestas velit ligula nunc tortor ultricies quam consequat hac inceptos congue ullamcorper nisl.
                    [created_at] => 2021-09-25T15:23:25+00:00
                    [lang] => en
                )

            [1] => Array
                (
                    [id] => tky4EtIvlp1b
                    [user_id] => 1
                    [description] => Suspendisse ante commodo duis dignissim, elit mi orci vulputate hac curabitur duis dignissim
                    [created_at] => 2021-09-25T15:23:25+00:00
                    [lang] => en
                )
        )

    [aggregations] => Array
        (
        )

    [stats] => Array
        (
            [total] => 2
        )
)

Create & Update Document

use App\Models\MyModel;

// Create document
$create = (new MyModel)->create(
    [
        'id' => 'abcd1234',
        'user_id' => 1,
        'description' => 'Lorem ipsum...',
        'created_at' => '2021-09-25T15:23:25+00:00',
        'lang' => 'en',
    ],
    false, // upsert (bool, default = false)
    false, // should queue (bool, default = false)
);

// Update document
$update = (new MyModel)->update(
    'my_doc_id',
    [
        'description' => 'Lorem ipsum text...',
    ],
    false, // should queue (bool, default = false)
);

// Update by script
$update = (new MyModel)->script(
    'my_doc_id',
    [
        'ctx._source.views = 0;',
    ],
    false, // should queue (bool, default = false)
);

Delete Document

use App\Models\MyModel;

$delete = (new MyModel)->delete(
    'my_doc_id',
    false, // should queue (bool, default = false)
);

// Delete by Query
$items = (new MyModel)->deleteByQuery(
    [
      'bool' => [
        'must' => [
          [
            'match' => [ 'user_id' => 1 ]
          ]
        ]
      ]
    ],
    true // shouldQueue
);

Get Document

use App\Models\MyModel;

$item = (new MyModel)->get('my_doc_id');

// Results
stdClass Object
(
    [success] => ok
    [source] => stdClass Object
        (
            [id] => J6SzTtlUFpTQFUm5LABP
            [user_id] => 1
            [description] => 'Lorem text...',
            [likes] => 0
            [created_at] => 2021-09-25T15:23:25+00:00
        )

)

Bulk Actions

use Etsetra\Elasticsearch\Console\BulkApi;

BulkApi::chunk(
  'my_model', // index name
  'J6SzTtlUFpTQ', // doc id
  [ 'ctx._source.views += 1' ], // doc body
  'script' // action type
);

// Action Types;
// script: elasticsearch java scripts,
// index: upsert document,
// create: create document,

// Alternate
BulkApi::chunk(
  'my_model',
  'J6SzTtlUFpTQ',
  [
    'user_id' => 2,
    'video_id' => 'dummy1234'
  ],
  'index' // action type
);

All versions of elasticsearch with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
etsetra/library Version ^1.0.0
predis/predis Version ^1.1
elasticsearch/elasticsearch Version ^7.14
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package etsetra/elasticsearch contains the following files

Loading the files please wait ....