小编典典

elasticsearch.exceptions.RequestError:RequestError(400,'mapper_parsing_exception','在字段[文本]上声明的[string]类型没有处理程序')

elasticsearch

我使用elasticsearch python api创建映射,但是出现了一些错误:

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)

它显示了elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'No handler for type [string] declared on field [texts]'),并且我找到了一些他们说的解决方案:使用text而不是string在字段类型中使用,但是它也出错了: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?


阅读 3961

收藏
2020-06-22

共1个答案

小编典典

这个

‘index’:’analyzed’或’index’:’not_analyzed’

是较旧的Elasticsearch版本映射,不需要。

您需要做的就是对分析的字符串字段使用“ text ”,对未经分析的文本字段使用“ keyword ”,如下所示:

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)

请在此处查看Elastic
docs中的参考:https
:
//www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html

2020-06-22