<commit_before># Elastomer

Making a stupid simple ElasticSearch client so your project can be smarter!

## Getting Started

Use [Boxen](https://setup.githubapp.com) to get your machine set up. Then:

```
$ git clone https://github.com/github/elastomer.git
$ cd elastomer
$ script/bootstrap
$ script/testsuite
```

## Client

The client provides a one-to-one mapping to the ElasticSearch [API
endpoints](http://www.elasticsearch.org/guide/reference/api/). The API is
decomposed into logical sections and accessed according to what you are trying
to accomplish. Each logical section is represented as a [client
class](lib/elastomer/client) and a top-level accessor is provided for each.

#### Cluster

API endpoints dealing with cluster level information and settings are found in
the [Cluster](lib/elastomer/client/cluster.rb) class.

```ruby
require 'elastomer/client'
client = Elastomer::Client.new

# the current health summary
client.cluster.health

# detailed cluster state information
client.cluster.state

# the list of all index templates
client.cluster.templates
```

#### Index

The methods in the [Index](lib/elastomer/client/index.rb) class deal with the
management of indexes in the cluster. This includes setting up type mappings
and adjusting settings. The actual indexing and search of documents are
handled by the Docs class (discussed next).

```ruby
require 'elastomer/client'
client = Elastomer::Client.new

index = client.index('twitter')
index.create(
  :settings => { 'index.number_of_shards' => 3 },
  :mappings => {
    :tweet => {
      :_source => { :enabled => true },
      :_all    => { :enabled => false },
      :properties => {
        :author => { :type => 'string', :index => 'not_analyzed' },
        :tweet  => { :type => 'string', :analyze => 'standard' }
      }
    }
  }
)

index.exists?

index.exists? :type => 'tweet'

index.delete
```

#### Docs

This decomposition is the most questionable, but it's a starting point. The
[Docs](lib/elastomer/client/docs.rb) class handles the indexing and searching
of documents. Each instance is scoped to an index and optionally a document
type.

```ruby
require 'elastomer/client'
client = Elastomer::Client.new

docs = client.docs('twitter')

docs.index({
  :_id    => 1,
  :_type  => 'tweet',
  :author => '@pea53',
  :tweet  => 'announcing Elastomer, the stupid simple ElasticSearch client'
})

docs.search({:query => {:match_all => {}}}, :search_type => 'count')
```
<commit_msg>add performance notes to README<commit_after># Elastomer

Making a stupid simple ElasticSearch client so your project can be smarter!

## Getting Started

Use [Boxen](https://setup.githubapp.com) to get your machine set up. Then:

```
$ git clone https://github.com/github/elastomer.git
$ cd elastomer
$ script/bootstrap
$ script/testsuite
```

## Client

The client provides a one-to-one mapping to the ElasticSearch [API
endpoints](http://www.elasticsearch.org/guide/reference/api/). The API is
decomposed into logical sections and accessed according to what you are trying
to accomplish. Each logical section is represented as a [client
class](lib/elastomer/client) and a top-level accessor is provided for each.

#### Cluster

API endpoints dealing with cluster level information and settings are found in
the [Cluster](lib/elastomer/client/cluster.rb) class.

```ruby
require 'elastomer/client'
client = Elastomer::Client.new

# the current health summary
client.cluster.health

# detailed cluster state information
client.cluster.state

# the list of all index templates
client.cluster.templates
```

#### Index

The methods in the [Index](lib/elastomer/client/index.rb) class deal with the
management of indexes in the cluster. This includes setting up type mappings
and adjusting settings. The actual indexing and search of documents are
handled by the Docs class (discussed next).

```ruby
require 'elastomer/client'
client = Elastomer::Client.new

index = client.index('twitter')
index.create(
  :settings => { 'index.number_of_shards' => 3 },
  :mappings => {
    :tweet => {
      :_source => { :enabled => true },
      :_all    => { :enabled => false },
      :properties => {
        :author => { :type => 'string', :index => 'not_analyzed' },
        :tweet  => { :type => 'string', :analyze => 'standard' }
      }
    }
  }
)

index.exists?

index.exists? :type => 'tweet'

index.delete
```

#### Docs

This decomposition is the most questionable, but it's a starting point. The
[Docs](lib/elastomer/client/docs.rb) class handles the indexing and searching
of documents. Each instance is scoped to an index and optionally a document
type.

```ruby
require 'elastomer/client'
client = Elastomer::Client.new

docs = client.docs('twitter')

docs.index({
  :_id    => 1,
  :_type  => 'tweet',
  :author => '@pea53',
  :tweet  => 'announcing Elastomer, the stupid simple ElasticSearch client'
})

docs.search({:query => {:match_all => {}}}, :search_type => 'count')
```

#### Performance

By default Elastomer uses Net::HTTP (via Faraday) to communicate with
ElasticSearch. You may find that Excon performs better for your use. To enable
Excon, add it to your bundle and then change your Elastomer initialization
thusly:

```
Elastomer::Client.new(url: YOUR_ES_URL, adapter: :excon)
```
{'fraction_non_alphanumeric': 0.12291033434650456, 'fraction_numerical': 0.001519756838905775, 'mean_word_length': 4.1923076923076925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 49, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '33691', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1555, 'n_words': 547}