【问题标题】:elasticsearch: create index with mappingselasticsearch:使用映射创建索引
【发布时间】:2016-01-13 01:21:38
【问题描述】:

当我第一次创建索引然后通过映射添加类型时,这一切都有效。但是当我尝试在一次调用中创建一个带有映射的索引时,我得到了错误:

"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [my_type]: Expected map for property [fields] on field [type] but got a class java.lang.String",

如何解决?我的代码如下:

创建:

PUT /my_index
{
    "settings": {
        "number_of_shards": 1,  
        "analysis": {
            "filter": {
                "my_shingle_filter": {
                    "type":             "shingle",
                    "min_shingle_size": 2, 
                    "max_shingle_size": 3, 
                    "output_unigrams":  false,   
                    "filler_token": ""
                },
                "kill_fillers": {
                    "type": "pattern_replace",
                    "pattern": ".*_.*",
                    "replace": ""
                }
            },
            "analyzer": {
                "my_shingle_analyzer": {
                    "type":             "custom",
                    "tokenizer":        "standard",
                    "filter": [
                        "standard"
                        ,"lowercase"
                        ,"stop"
                        ,"porter_stem"
                        ,"my_shingle_filter" 
                        ,"trim"
                    ]
                }}}}}

添加类型:

PUT /my_index/_mapping/my_type
{
    "my_type": {
        "properties": {
            "title": {
                "type": "string",
                "fields": {
                    "shingles": {
                        "type":     "string",
                        "analyzer": "my_shingle_analyzer"
                    }}}}}}

与映射一起创建索引:

PUT /my_index
{
  "settings": {
    "number_of_shards": 1,
    "analysis": {
      "filter": {
        "my_shingle_filter": {
          "type": "shingle",
          "min_shingle_size": 2,
          "max_shingle_size": 2,
          "output_unigrams": false
        }
      },
      "analyzer": {
        "my_shingle_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "my_shingle_filter"
          ]
        }}}
  },
  "mappings": {
    "my_type": {
      "properties": {
        "type": "string",
        "fields": {
          "shingles": {
            "type": "string",
            "analyzer": "my_shingle_analyzer"
          }}}}}}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您只是在第二个查询中缺少 title 字段:

    PUT /my_index
    {
      "settings": {
        "number_of_shards": 1,
        "analysis": {
          "filter": {
            "my_shingle_filter": {
              "type": "shingle",
              "min_shingle_size": 2,
              "max_shingle_size": 2,
              "output_unigrams": false
            }
          },
          "analyzer": {
            "my_shingle_analyzer": {
              "type": "custom",
              "tokenizer": "standard",
              "filter": [
                "lowercase",
                "my_shingle_filter"
              ]
            }}}
      },
      "mappings": {
        "my_type": {
          "properties": {
           "title": {                    <--- this line is missing
            "type": "string",
            "fields": {
              "shingles": {
                "type": "string",
                "analyzer": "my_shingle_analyzer"
              }}}}}}}                    <--- + one closing brace
    

    【讨论】:

    • 总是乐于提供帮助!
    猜你喜欢
    • 1970-01-01
    • 2020-09-23
    • 2014-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-11
    • 1970-01-01
    相关资源
    最近更新 更多