ElasticSearch汇总请查看:ElasticSearch教程——汇总篇
通过如下代码手动建立mapping的时候报错
PUT /website
{
"mappings": {
"article": {
"properties": {
"author_id": {
"type": "long"
},
"title": {
"type": "text",
"analyzer": "english"
},
"content": {
"type": "text"
},
"post_date": {
"type": "date"
},
"publisher_id": {
"type": "text",
"index": "not_analyzed"
}
}
}
}
}
错误如下
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [article]: Could not convert [publisher_id.index] to boolean"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [article]: Could not convert [publisher_id.index] to boolean",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Could not convert [publisher_id.index] to boolean",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Failed to parse value [not_analyzed] as only [true] or [false] are allowed."
}
}
},
"status": 400
}
百度了下,国内几乎没有任何相关文档或者博客有说如何解决,不过在stackoverflow.上倒是有解决方案,连接如下:
官方文档上也有说明:Elasticsearch Reference [6.4] » Analysis » Analyzers » Keyword Analyzer
大致说的是现在index这个只能用true或者false了,如果想要不被分词就把数据类型设置为keyword
PUT /newwebsite
{
"mappings": {
"article": {
"properties": {
"author_id": {
"type": "long"
},
"title": {
"type": "text",
"analyzer": "english"
},
"content": {
"type": "text"
},
"post_date": {
"type": "date"
},
"publisher_id": {
"type": "keyword"
}
}
}
}
}
测试
GET /newwebsite/_analyze
{
"field": "publisher_id",
"text": "my-dogs"
}
返回结果
{
"tokens": [
{
"token": "my-dogs",
"start_offset": 0,
"end_offset": 7,
"type": "word",
"position": 0
}
]
}