elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'No handler for type [string] declared on field [texts]')

19,341

this

'index': 'analyzed' OR 'index': 'not_analyzed'

is an older elasticsearch version mapping and not needed.

All you need to do is use 'text' for analyzed string fields and 'keyword' for not_analyzed text fields, like this:

es = Elasticsearch("localhost:9200")
request_body = {
    "settings": {
        "number_of_shards": 5,
        "number_of_replicas": 1
    },
    'mappings': {
        'examplecase': {
            'properties': {
                'tbl_id': {'type': 'keyword'},
                'texts': {'type': 'text'},
            }
        }
    }
}
es.indices.create(index='example_index', body=request_body)

see reference in Elastic docs here: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html

Share:
19,341
littlely
Author by

littlely

Updated on June 27, 2022

Comments

  • littlely
    littlely almost 2 years

    I use elasticsearch python api to create mappings, but it went some wrong:

    es = Elasticsearch("localhost:9200")
    request_body = {
        "settings": {
            "number_of_shards": 5,
            "number_of_replicas": 1
        },
        'mappings': {
            'examplecase': {
                'properties': {
                    'tbl_id': {'index': 'not_analyzed', 'type': 'string'},
                    'texts': {'index': 'analyzed', 'type': 'string'},
                }
            }
        }
    }
    es.indices.create(index='example_index', body=request_body)
    

    it shows elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'No handler for type [string] declared on field [texts]'), and I find some solution that they say: use text instead of string in the field type, but it also went wrong: elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'Failed to parse mapping [examplecase]: Could not convert [texts.index] to boolean'). The elasticsearch version iselasticsearch-6.5.4. How can I deal with it?