<commit_before>This is a package that allows indexing of django models using elasticsearch. It
requires django, elasticsearch-py, elasticsearch-dsl and a running instance of
elasticsearch.

# Features:
- Management commands (rebuild_index and update_index, clear_index)
- Django signal receivers on save and delete for keeping ES in sync
- Complex field type support (ObjectField, NestedField, ListField)
- Based of the features of elasticsearch-dsl

# Quick Start:
Add ‘elasticmodels’ to INSTALLED_APPS

You must define ELASTICSEARCH_CONNECTIONS in your django settings.

For example:
```python
ELASTICSEARCH_CONNECTIONS = {
    'default': {
        'hosts': ['http://localhost:9200',],
        'index_name': 'my_index',
    }
    'fish': {
        'hosts': ['http://example.com:9200',],
        'index_name': 'fish',
    }
}
```

Now consider a model like this:

```python
class Car(models.Model):
    license = models.CharField(primary_key=True)
    color = models.CharField()
    description = models.TextField()
    type = models.IntegerField(choices=[
        (1, "Sedan"),
        (2, "Truck"),
        (4, "SUV"),
    ])
```
    
Place this line of code at the **bottom** of the `models.py` file.

```python
from .indexes import * # noqa isort:skip
```

This is required for indexing, but placing it at the top would
cause a circular import.

Now, to make this model work with Elasticsearch, create a subclass of
`elasticmodels.Index` in a file called `indexes.py`:

```python
from elasticmodels import Index, StringField, IntegerField, NestedField
from .models import Car


class CarIndex(Index):
    class Meta:
        model = Car
        fields = [
            'license',
            'color',
            'description',
            'type',
        ]
```

Elasticmodels will automatically setup a mapping in Elasticsearch for the Car
model, where the Elasticsearch fields are derived from the `fields` attribute
on the Meta class.

To create the Elasticsearch index and mappings, use the rebuild_index<commit_msg>Clarify why the Index needs to be imported<commit_after>This is a package that allows indexing of django models using elasticsearch. It
requires django, elasticsearch-py, elasticsearch-dsl and a running instance of
elasticsearch.

# Features:
- Management commands (rebuild_index and update_index, clear_index)
- Django signal receivers on save and delete for keeping ES in sync
- Complex field type support (ObjectField, NestedField, ListField)
- Based of the features of elasticsearch-dsl

# Quick Start:
Add ‘elasticmodels’ to INSTALLED_APPS

You must define ELASTICSEARCH_CONNECTIONS in your django settings.

For example:
```python
ELASTICSEARCH_CONNECTIONS = {
    'default': {
        'hosts': ['http://localhost:9200',],
        'index_name': 'my_index',
    }
    'fish': {
        'hosts': ['http://example.com:9200',],
        'index_name': 'fish',
    }
}
```

Now consider a model like this defined in our app's `models.py` file:

```python
class Car(models.Model):
    license = models.CharField(primary_key=True)
    color = models.CharField()
    description = models.TextField()
    type = models.IntegerField(choices=[
        (1, "Sedan"),
        (2, "Truck"),
        (4, "SUV"),
    ])
```

To make this model work with Elasticsearch, create a subclass of
`elasticmodels.Index`. You can define the class wherever you want. We'll put in
a file called `indexes.py` inside our Django app:

```python
from elasticmodels import Index, StringField, IntegerField, NestedField
from .models import Car


class CarIndex(Index):
    class Meta:
        model = Car
        fields = [
            'license',
            'color',
            'description',
            'type',
        ]
```

The Index subclass needs to be imported during the normal execution of your
program. A good way to make that happen is to place this line of code at the
**bottom** of the `models.py` file:

```python
from .indexes import * # noqa isort:skip
```

We have to put it at the bottom of the file, otherwise, we'd have a circular
import problem. (The `# noqa isort:skip` stuff is useful if you're using the
`flake8` and `isort` packages.)

Elasticmodels will automatically setup a mapping in Elasticsearch for the Car
model, where the Elasticsearch fields are derived from the `fields` attribute
on the Meta class.

To create the Elasticsearch index and mappings, use the rebuild_index
{'fraction_non_alphanumeric': 0.09561662502838973, 'fraction_numerical': 0.005223711106064047, 'mean_word_length': 3.4710659898477156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '549453', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1241, 'n_words': 498}