elasticsearch - 创建索引时如何解决 “Failed to parse content to map”错误?

标签 elasticsearch

我收到一个错误。

错误:

"{"error":{"root_cause":[{"type":"parse_exception","reason":"Failed to parse content to map"}],"type":"parse_exception","reason":"Failed to parse content to map","caused_by":{"type":"json_parse_exception","reason":"Unexpected character ('s' (code 115)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@38a4cd00; line: 2, column: 3]"}},"status":400}" error while trying to create index



代码:
{
  "settings" : {
        "number_of_shards" : 1,
        "number_of_replicas" : 1
    },
   "mappings": {
             "properties": {
        "anonymous": {"type": "boolean"},
        "content_text_form": {"type": "text"},
        "details": {"type": "text"},
        "language": {"type": "keyword"},
        "no_of_comments": {"type": "long"},
        "up_votes": {"type": "long"},
        "down_votes": {"type": "long"},
        "no_of_views": {"type": "long"},
        "no_of_impressions": {"type": "long"},
        "short_id": {"type": "keyword"},
        "no_of_reposts": {"type": "long"},
        "createdAt": {"type": "date"},
        "updatedAt": {"type": "date"},
        "re_post_date": {"type": "date"},
        "media_urls": {
                        "properties": {
                          "url": {"type": "keyword"},
                          "type": {"type": "keyword"},
                          "uploadedOn": {"type": "date"},
                          "description": {"type": "text"},
                          "thumbnail": {"type": "text"},
                          "file_type": {"type": "keyword"},
                          "dimensions": {
                            "properties": {
                              "type": {
                                "properties": {
                                  "height": {"type": "long"},
                                  "width": {"type": "long"},
                                  "aspect_ratio":{"type":"long"}
                                },
                              "required": {"type": "boolean"}
                              }
                            }}
                          }
                          },
      "tags": {"type": "keyword"},
         "tag_positions": {
                          "properties": {
                            "tag": {"type": "keyword"},
                            "tag_start": {"type": "long"},
                            "tag_end": {"type": "long"}}},
          "source": {
          "properties": {
            "title" : {"type": "text"},
            "description": {"type": "text"},
            "media_type": {"type": "text"},
            "url": {"type": "text"}
          }
        },
           "moderation": {
          "properties": {
            "done": {"type":"boolean"}
          }
        }
       }
     }
}

最佳答案

我不确定您使用的是哪个版本的Elasticsearch,但我使用的是6.7,这是经过两次修改后才能工作的版本

1) I added "_doc"
2) I moved `"required": { "type": "boolean"}`  to one curly below ... look at it and it will make sense

这是对我有用的映射
  PUT so_test6
   {
      "settings" : {
         "number_of_shards" : 1,
         "number_of_replicas" : 1
      },
    "mappings": {
        "_doc":{
         "properties": {
           "anonymous": {"type": "boolean"},
           "content_text_form": {"type": "text"},
           "details": {"type": "text"},
           "language": {"type": "keyword"},
           "no_of_comments": {"type": "long"},
           "up_votes": {"type": "long"},
           "down_votes": {"type": "long"},
           "no_of_views": {"type": "long"},
           "no_of_impressions": {"type": "long"},
           "short_id": {"type": "keyword"},
           "no_of_reposts": {"type": "long"},
           "createdAt": {"type": "date"},
           "updatedAt": {"type": "date"},
           "re_post_date": {"type": "date"},
           "media_urls": {
                    "properties": {
                      "url": {"type": "keyword"},
                      "type": {"type": "keyword"},
                      "uploadedOn": {"type": "date"},
                      "description": {"type": "text"},
                      "thumbnail": {"type": "text"},
                      "file_type": {"type": "keyword"},
                      "dimensions": {
                        "properties": {
                          "type": {
                            "properties": {
                              "height": {"type": "long"},
                              "width": {"type": "long"},
                              "aspect_ratio":{"type":"long"}
                            }


                          },
                          "required": {"type": "boolean"}
                        }}
                      }
                      },
         "tags": {"type": "keyword"},
          "tag_positions": {
                      "properties": {
                        "tag": {"type": "keyword"},
                        "tag_start": {"type": "long"},
                        "tag_end": {"type": "long"}}},
      "source": {
      "properties": {
        "title" : {"type": "text"},
        "description": {"type": "text"},
        "media_type": {"type": "text"},
        "url": {"type": "text"}
      }
    },
       "moderation": {
      "properties": {
        "done": {"type":"boolean"}
      }
    }
   }
  }
 }
}

关于elasticsearch - 创建索引时如何解决 “Failed to parse content to map”错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56407626/

相关文章:

ruby-on-rails - elasticsearch模型更新到7.0破坏测试

python - 以下哪个是从python查询elasticsearch的最佳方法?

elasticsearch - 为什么此Elasticsearch查询不返回任何结果?

elasticsearch - 阻止特定日期范围的接送

elasticsearch - Elasticsearch匹配精确的浮点值

java - 为什么elasticsearch matchQuery不返回结果?

java - ElasticSearch JavaAPI (SearchScroll)-search_context_missing_exception","reason":"No search context found for id

ruby-on-rails-3 - 将SQL与 Elasticsearch 结合使用

elasticsearch - Elasticsearch部分,不区分大小写的匹配

elasticsearch - 在Elasticsearch中使用 `not`过滤器