<commit_before>### Flexible elasticseach builder to run complex queries with an easier way.

#####1) Install package via composer:

	composer require basemkhirat/elasticsearch

#####2) Add package service provider:

	Basemkhirat\Elasticsearch\ElasticsearchServiceProvider::class
	
#####3) Add package alias:

	'ES' => Basemkhirat\Elasticsearch\Facades\ES::class
	
#####4) Publishing:
    
    php artisan vendor:publish --provider="Basemkhirat\Elasticsearch\ElasticsearchServiceProvider"
	
### Usage:

#### Setting your connections

  
  After publishing, the config file is placed here `config/es.php`
  where you can add more than one elasticsearch node.


#### Creating a new index

    ES::index("my_index")->create();
    
    # or 
    
    ES::create("my_index");
    
    
>

    # [optional] you can create index with custom options
    
    ES::index("my_index")->create(function($index){
            
        $index->shards(5)->replicas(1)->mapping([
            'my_type' => [
                'properties' => [
                    'first_name' => [
                        'type' => 'string',
                    ],
                    'age' => [
                        'type' => 'integer'
                    ]
                ]
            ]
        ])
        
    });
    
    # or
    
    ES::create("my_index", function($index){
      
          $index->shards(5)->replicas(1)->mapping([
              'my_type' => [
                  'properties' => [
                      'first_name' => [
                          'type' => 'string',
                      ],
                      'age' => [
                          'type' => 'integer'
                      ]
                  ]
              ]
          ])
      
    });


#### Dropping index

    ES::index("my_index")->drop();
        
    # or
    
    ES::drop("my_index");
    
#### Running queries:

    $documents = ES::connection("default")
                    ->index("my_index")
                    ->type("my_type")
                    ->get();    // return collection of results

you can rewite the above query to

    $documents = ES::get();    // return collection of results
    
the query builder will use the default connection, index, and type names setted in configuration file `es.php`. 
 
Index and type names setted in query will override values the configuration file


#### Available methods:

##### Getting document by id

    $documents = ES::_id(3)->get();

##### Sorting
    
    $documents = ES::orderBy("created_at", "desc")->get();
    $documents = ES::orderBy("_score")->get();
    
##### Limit and offset
    
    $documents = ES::take(10)->skip(5)->get();
    
##### Select only specific fields
    
    $documents = ES::select("title", "content")->take(10)->skip(5)->get();
    
##### Where clause
    
    ES::where("views", 150)->get(); or ES::where("views", "=", 150)->get();

##### Where greater than

    ES::where("views", ">", 150)->get();
    
##### Where greater than or equal

    ES::where("views", ">=", 150)->get();
    
##### Where less than

    ES::where("views", "<", 150)->get();
    
##### Where greater than or equal

    ES::where("views", "<=", 150)->get();
    
##### Where like

    ES::where("title", "like", "foo")->get();
    
##### Where field exists

    ES::where("hobbies", "exists", true)->get(); or ES::whereExists("hobbies", true)->get();
    
##### Where in clause
    
    ES::whereIn("id", [100, 150])->get();
    
##### Where between clause 
    
    ES::whereBetween("id", 100, 150)->get();
   
  >
    
##### Where not clause
    
    ES::whereNot("views", 150)->get(); or ES::where("views", "=", 150)->get();

##### Where not greater than

    ES::whereNot("views", ">", 150)->get();

##### Where not greater than or equal

    ES::whereNot("views", ">=", 150)->get();
    
##### Where not less than

    ES::whereNot("views", "<", 150)->get();
    
##### Where not less than or equal

    ES::whereNot("views", "<=", 150)->get();
    
##### Where not like

    ES::whereNot("title", "like", "foo")->get();
    
##### Where not field exists

    ES::whereNot("hobbies", "exists", true)->get(); or ES::whereExists("hobbies", true)->get();
    
##### Where not in clause
    
    ES::whereNotIn("id", [100, 150])->get();
    
##### Where not between clause 
    
    ES::whereNotBetween("id", 100, 150)->get();
    
    
  >
  
##### Search the entire document
    <commit_msg>fix the usage of where field not exists<commit_after>### Flexible elasticseach builder to run complex queries with an easier way.

#####1) Install package via composer:

	composer require basemkhirat/elasticsearch

#####2) Add package service provider:

	Basemkhirat\Elasticsearch\ElasticsearchServiceProvider::class
	
#####3) Add package alias:

	'ES' => Basemkhirat\Elasticsearch\Facades\ES::class
	
#####4) Publishing:
    
    php artisan vendor:publish --provider="Basemkhirat\Elasticsearch\ElasticsearchServiceProvider"
	
### Usage:

#### Setting your connections

  
  After publishing, the config file is placed here `config/es.php`
  where you can add more than one elasticsearch node.


#### Creating a new index

    ES::index("my_index")->create();
    
    # or 
    
    ES::create("my_index");
    
    
>

    # [optional] you can create index with custom options
    
    ES::index("my_index")->create(function($index){
            
        $index->shards(5)->replicas(1)->mapping([
            'my_type' => [
                'properties' => [
                    'first_name' => [
                        'type' => 'string',
                    ],
                    'age' => [
                        'type' => 'integer'
                    ]
                ]
            ]
        ])
        
    });
    
    # or
    
    ES::create("my_index", function($index){
      
          $index->shards(5)->replicas(1)->mapping([
              'my_type' => [
                  'properties' => [
                      'first_name' => [
                          'type' => 'string',
                      ],
                      'age' => [
                          'type' => 'integer'
                      ]
                  ]
              ]
          ])
      
    });


#### Dropping index

    ES::index("my_index")->drop();
        
    # or
    
    ES::drop("my_index");
    
#### Running queries:

    $documents = ES::connection("default")
                    ->index("my_index")
                    ->type("my_type")
                    ->get();    // return collection of results

you can rewite the above query to

    $documents = ES::get();    // return collection of results
    
the query builder will use the default connection, index, and type names setted in configuration file `es.php`. 
 
Index and type names setted in query will override values the configuration file


#### Available methods:

##### Getting document by id

    $documents = ES::_id(3)->get();

##### Sorting
    
    $documents = ES::orderBy("created_at", "desc")->get();
    $documents = ES::orderBy("_score")->get();
    
##### Limit and offset
    
    $documents = ES::take(10)->skip(5)->get();
    
##### Select only specific fields
    
    $documents = ES::select("title", "content")->take(10)->skip(5)->get();
    
##### Where clause
    
    ES::where("views", 150)->get(); or ES::where("views", "=", 150)->get();

##### Where greater than

    ES::where("views", ">", 150)->get();
    
##### Where greater than or equal

    ES::where("views", ">=", 150)->get();
    
##### Where less than

    ES::where("views", "<", 150)->get();
    
##### Where greater than or equal

    ES::where("views", "<=", 150)->get();
    
##### Where like

    ES::where("title", "like", "foo")->get();
    
##### Where field exists

    ES::where("hobbies", "exists", true)->get(); or ES::whereExists("hobbies", true)->get();
    
##### Where in clause
    
    ES::whereIn("id", [100, 150])->get();
    
##### Where between clause 
    
    ES::whereBetween("id", 100, 150)->get();
   
  >
    
##### Where not clause
    
    ES::whereNot("views", 150)->get(); or ES::where("views", "=", 150)->get();

##### Where not greater than

    ES::whereNot("views", ">", 150)->get();

##### Where not greater than or equal

    ES::whereNot("views", ">=", 150)->get();
    
##### Where not less than

    ES::whereNot("views", "<", 150)->get();
    
##### Where not less than or equal

    ES::whereNot("views", "<=", 150)->get();
    
##### Where not like

    ES::whereNot("title", "like", "foo")->get();
    
##### Where not field exists

    ES::whereNot("hobbies", "exists", true)->get(); or ES::whereExists("hobbies", false)->get();
    
##### Where not in clause
    
    ES::whereNotIn("id", [100, 150])->get();
    
##### Where not between clause 
    
    ES::whereNotBetween("id", 100, 150)->get();
    
    
  >
  
##### Search the entire document
    
{'fraction_non_alphanumeric': 0.1883226459669254, 'fraction_numerical': 0.016874789065136685, 'mean_word_length': 2.132487667371388, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 127, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1481142', 'n_tokens_mistral': 2808, 'n_tokens_neox': 2523, 'n_words': 625}