S
S
ssssergey2017-06-12 13:38:23
Python
ssssergey, 2017-06-12 13:38:23

How to explicitly set the field type (keword) in Elasticsearch (python) when creating a document?

for i in rage(100):
    body = {'title': 'The Title{}'.format(i), 'text': 'big big big text'}
    result = es.index(index='index', doc_type='type', body=body)

The index is filled in the loop. As a result, we need the ability to perform an exact search (term) on the 'title' field and a full-text search (match) on the 'text' field.
Everything is fine with the 'text' field - the default type is 'text'. But 'title' probably needs to be explicitly typed as 'keyword' when creating a document. How to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
A1estro, 2017-06-12
@ssssergey

You need to create a mapping - https://www.elastic.co/guide/en/elasticsearch/refe...
https://www.elastic.co/guide/en/elasticsearch/refe...

A
Alexey Cheremisin, 2017-06-13
@leahch

As already written, you need to make a mapping to your fields. In addition, you can also make fields for each field https://www.elastic.co/guide/en/elasticsearch/ref...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question