验证失败:1:缺少映射类型;在弹性搜索中

时间:2016-03-05 12:25:02

标签: elasticsearch lucene

我的错误是this questuion。 作为这个问题的答案,我正在尝试将正确的URL设置为PUT索引映射,但它在我的实例上不起作用:

$ cat mapping.json | http PUT myhost:9200/acastest/_mapping 

结果:

HTTP/1.1 400 Bad Request
Content-Length: 247
Content-Type: application/json; charset=UTF-8

{
    "error": {
        "reason": "Validation Failed: 1: mapping type is missing;", 
        "root_cause": [
            {
                "reason": "Validation Failed: 1: mapping type is missing;", 
                "type": "action_request_validation_exception"
            }
        ], 
        "type": "action_request_validation_exception"
    }, 
    "status": 400
}

尝试这个:

$ cat mapping.json | http PUT myhost:9200/acastest/articles/_mapping 

结果:

HTTP/1.1 400 Bad Request
Content-Length: 3969
Content-Type: application/json; charset=UTF-8

{
    "error": {
        "reason": "Root mapping definition has unsupported parameters:  [mappings : {articles={properties={category_en={type=string, index=not_analyzed},blah blah blah", 
        "root_cause": [
            {
                "reason": "Root mapping definition has unsupported parameters:  [mappings : {articles={properties={category_en={type=string, index=not_analyzed}, category_fa={blahblah blah", 
                "type": "mapper_parsing_exception"
            }
        ], 
        "type": "mapper_parsing_exception"
    }, 
    "status": 400
}

Elasticsearch config:

"version": {

    "number": "2.1.1",
    "build_hash": "40e2c53a6b6c2972b3d13846e450e66f4375bd71",
    "build_timestamp": "2015-12-15T13:05:55Z",
    "build_snapshot": false,
    "lucene_version": "5.3.1"

},

和我的映射文件如下:

{ 
    "mappings": {
            "articles": {
                "properties": {
                    "category_en": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "category_fa": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    blah
                    blah
                    blah
                }
            }
        }
}

要查看完整的地图文件,请检查this 我该如何解决?

2 个答案:

答案 0 :(得分:2)

您有两种解决方案:

一个。如果你想运行

$ cat mapping.json | http PUT myhost:9200/acastest/articles/_mapping 

您需要像这样更改mapping.json文件:

    { 
        "articles": {
            "properties": {
                "category_en": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "category_fa": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                blah
                blah
                blah
            }
        }
    }

B中。或者您可以像现在一样保留mapping.json文件,但是您需要运行以下命令:

$ cat mapping.json | http PUT myhost:9200/acastest 

答案 1 :(得分:1)

我的解决方案:

将网址更改为:

http://myhost:9200/acastest/_mapping/articles 

将mapping.josn更改为:

{
    "articles": {
        "properties": {
            "category_en": {
                "type": "string",
                "index": "not_analyzed"
            },
            "category_fa": {
                "type": "string",
                "index": "not_analyzed"
            },
            blah
            blah
            blah
        }
    }
}