手动建立和修改mapping以及定制string类型数据是否分词

手动建立和修改mapping以及定制string类型数据是否分词
1、如何建立索引

analyzed 分词
not_analyzed 不分词
no 不被索引搜索

2、修改mapping

只能创建index时手动建立mapping,或者新增field mapping,但是不能update field 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”
​ }
​ }
​ }
}
}

PUT /website
{
“mappings”: {
​ “article”: {
​ “properties”: {
​ “author_id”: {
​ “type”: “text”
​ }
​ }
​ }
}
}

{
“error”: {
​ “root_cause”: [
​ {
​ “type”: “index_already_exists_exception”,
​ “reason”: “index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists”,
​ “index_uuid”: “co1dgJ-uTYGBEEOOL8GsQQ”,
​ “index”: “website”
​ }
​ ],
​ “type”: “index_already_exists_exception”,
​ “reason”: “index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists”,
​ “index_uuid”: “co1dgJ-uTYGBEEOOL8GsQQ”,
​ “index”: “website”
},
“status”: 400
}

PUT /website/_mapping/article
{
“properties” : {
​ “new_field” : {
​ “type” : “string”,
​ “index”: “not_analyzed”
​ }
}
}

3、测试mapping

GET /website/_analyze
{
“field”: “content”,
“text”: “my-dogs”
}

GET website/_analyze
{
“field”: “new_field”,
“text”: “my dogs”
}

{
“error”: {
​ “root_cause”: [
​ {
​ “type”: “remote_transport_exception”,
​ “reason”: “[4onsTYV][127.0.0.1:9300][indices:admin/analyze[s]]”
​ }
​ ],
​ “type”: “illegal_argument_exception”,
​ “reason”: “Can’t process field [new_field], Analysis requests are only supported on tokenized fields”
},
“status”: 400
}

打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • © 2020 John Doe
  • Powered by Hexo Theme Ayer
  • PV: UV:

请我喝杯咖啡吧~

支付宝
微信