# Adding percolator settings and mapping with Python

**URL:** <https://discuss.elastic.co/t/adding-percolator-settings-and-mapping-with-python/131256>\
**Category:** Elasticsearch\
**Created:** [May 10, 2018, 6:38am UTC](https://discuss.elastic.co/t/adding-percolator-settings-and-mapping-with-python/131256 "2018-05-10T06:38:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![keremcan](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@keremcan](https://discuss.elastic.co/u/keremcan)\
**Post date:** [May 10, 2018, 6:38am UTC](https://discuss.elastic.co/t/adding-percolator-settings-and-mapping-with-python/131256/1 "2018-05-10T06:38:59Z")

</div>

I added default percolator index with the python code:

```
class Document(DocType):
    title = Text()   
    query = Percolator()

    class Meta:
        index = 'my-index'
        doc_type = '_doc'

    def save(self, **kwargs):
        return super(Document, self).save(**kwargs)

```

I also want to add this some settings with Python. Here is my whole query, mapping and setting. I can put this via `curl`

```
PUT /my-index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "standard_lowercase_example": {
          "type": "custom",
          "tokenizer": "whitespace",
          "filter": ["lowercase"]
        },
        "turkish_lowercase_example": {
          "type": "custom",
          "tokenizer": "whitespace",
          "filter": ["turkish_lowercase"]
        }
      },
      "filter": {
        "turkish_lowercase": {
          "type": "lowercase",
          "language": "turkish"
        }
      }
    }
  },
  "mappings": {
        "_doc": {
            "properties": {
                "title": {
                    "type": "text",
                    "analyzer": "standard_lowercase_example"
                },
                "query": {
                    "type": "percolator"
                }
            }
        }
    }
}

```

In shortly, I'm trying to add above curl request with my Python code. Here is my whole Python code. I think I should use `put_settings(**kwargs)` from [API](https://elasticsearch-dsl.readthedocs.io/en/latest/api.html#elasticsearch_dsl.Index.put_settings) but I couldn't figure that out how to combine.

```
import json

from elasticsearch_dsl import (
    connections,
    DocType,
    Mapping,
    Percolator,
    Text
)
from elasticsearch_dsl.query import (
    SpanNear,
    SpanTerm
)
from elasticsearch import Elasticsearch

# Read the json File
json_data = open('titles.json').read()
data = json.loads(json_data)

docs = data['response']['docs']

# creating a new default elasticsearch connection
connections.configure(
    default={'hosts': 'localhost:9200'},
)

class Document(DocType):
    title = Text()   
    query = Percolator()

    class Meta:
        index = 'my-index'
        doc_type = '_doc'

    def save(self, **kwargs):
        return super(Document, self).save(**kwargs)

# create the mappings in elasticsearch
Document.init()

# index the query
for doc in docs:
    terms = doc['title'].split(" ")

    clauses = []
    for abcd in terms:
        x = abcd.replace("İ", "i").replace(",", "").replace("î", "i").replace("I", "ı")
        term = x.lower()
        field = SpanTerm(title=term)
        clauses.append(field)
    query = SpanNear(clauses=clauses)
    item = Document(query=query)
    item.save()

```

Thanks in advance!

P.S: Also you can check [this question](https://stackoverflow.com/questions/50266899/adding-percolator-settings-and-mapping-with-python).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 7, 2018, 6:39am UTC](https://discuss.elastic.co/t/adding-percolator-settings-and-mapping-with-python/131256/2 "2018-06-07T06:39:05Z")

</div>

Closed on June 7, 2018, 6:39am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
