elasticsearch在window中报错:"Unexpected character ('m' (code 109)): was expecting double-quote to start

在Windows环境下配置Elasticsearch遭遇解析mapping文件错误,解决办法是正确引用curl命令及JSON内容,确保在Windows系统中正确运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

elasticsearch从入坑到放弃

今天在配置问答系统中使用到了elasticsearch,由于在Linux下开发界面不友好,就直接在Windows下配置环境进行开发,结果一不小心入了一个坑,折腾了三个多小时才弄出来,所以以后还是要用Linux开发。。。

从官网下载ES https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html

解压直接bin目录下运行 elasticsearch.bat,

通过elasticsearch的mapping文件创建index和type时,总是报错"Failed to parse content to map,Unexpected character ('m' (code 109)): was expecting double-quote to start field name

上官网查询格式,

https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html

官网生成的curl也是报错

curl -X PUT "localhost:9200/my_index" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "_doc": { 
      "properties": { 
        "title":    { "type": "text"  }, 
        "name":     { "type": "text"  }, 
        "age":      { "type": "integer" },  
        "created":  {
          "type":   "date", 
          "format": "strict_date_optional_time||epoch_millis"
        }
      }
    }
  }
}
'

最后发现在原因是Windows系统的问题:将curl后命令用双引号引用,json内容用三个双引号引用

curl -X PUT "localhost:9200/my_index" -H "Content-Type: application/json" -d"
{
  """mappings""": {
    """_doc""": { 
      """properties""": { 
        """title""":    { """type""": """text"""  }, 
        """name""":     { """type""": """text"""  }, 
        """age""":      { """type""": """integer""" },  
        """created""":  {
          """type""":   """date""", 
          """format""": """strict_date_optional_time||epoch_millis"""
        }
      }
    }
  }
}
"


 

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值