ElasticSearch之index
创始人
2024-11-14 12:06:14
0

创建index

请求url:

PUT localhost:9200/test 

请求体:

{           "settings": {                  "analysis": {                       "analyzer": {                           "comma": {                                "type": "pattern",                                "pattern":","                            }                       }                   }         },     "mappings": {          "article": {              "properties": {                  "id": { "type": "long" },                  "pubdate": { "type": "date" },                   "source": { "type": "text","analyzer": "standard"}, /*标准分词器*/                  "title": { "type": "text", "analyzer":"ik_max_word" }, /*ik分词器*/                   "summary": {"type": "text", "analyzer":"ik_smart" }, /*ik分词器*/                   "relatecolumn": {"type": "text", "analyzer":"pattern" },   /*按逗号分割,需要自定义符号分词器*/                   "stocks": {"type": "text","analyzer":"comma","fields": {"size": {"type": "token_count","analyzer": "comma"}}}, /*按逗号分割,并附加filed统计分词个数*/                   "photo": {"type": "keyword","null_value": "000000"}, /*null_value 空值处理 text类型不支持*/              }          }      }  } 

删除index

请求url:

DELETE localhost:9200/test 

index设置bak

POST http://192.168.2.200:9200/_reindex 
{    "source": {       "index": "pdf_msg"    },    "dest": {       "index": "pdf_msg.bak",       "version_type": "external"    } }   {    "source": {       "index": "pdf_msg.bak"    },    "dest": {       "index": "pdf_msg",       "version_type": "external"    } }  

index空值默认值

使用null_value替换显示的空值
删除上边定义的索引delete kaka,然后自定义mapping,给tags设置"null_value" : “null”,用指定的值替换显示的空值,"null"可以自定义为任意值

使用了null_value这样做的好处就是空字段也可以被索引,同时也不会在查询时报field name is null or empty的错误

put kaka  {  	 "mappings":{     		"properties":{       			"tags" :{        "type":"keyword",        "null_value":"null"      }    		 }  	} } 

再插入上边的数据

POST /kaka/_bulk { "index": { "_id": "1"}}{ "tags" : ["search"]}   { "index": { "_id": "2"}}{ "tags" : ["search", "open_source"] }  { "index": { "_id": "3"}}{ "tags" : null }   { "index": { "_id": "4"}}{ "tags" :"null"} 

再次执行查询为null的数据,就会出现第3、4条数据

post /kaka/_search  {   	"query":{    		 "term": {      "tags": "null"    }   	},   	"profile":"true" } 

使用null_value注意点
null_value必须和定义的数据类型匹配,例如long类型的不能定义字符串类型的value_null值

看一下long类型设置了字符串类型value_null会出现什么错误

错误演示,long类型使用了字符串类型的null_value值put kaka{ “mappings”:{ “properties”:{ “tags” :{ “type”:“long”, “null_value”:“null” } } }}

返回错误如下

{  "error": {    "root_cause": [      {        "type": "mapper_parsing_exception",        "reason": "Failed to parse mapping [_doc]: For input string: \"null\""      }    ],    "type": "mapper_parsing_exception",    "reason": "Failed to parse mapping [_doc]: For input string: \"null\"",    "caused_by": {      "type": "number_format_exception",      "reason": "For input string: \"null\""    }  },  "status": 400} 

注意了数据类型外,你还需要知道value_null不是任何类型都可以使用的,以下列举的类型都可使用null_value
Array
Boolean
Date
geo_point
ip
keyword
Numeric
point

创建文档document

请求url:

POST localhost:9200/blog1/article/1 

请求体:

{  "id":1,  "title":"ElasticSearch是一个基于Lucene的搜索服务器",  "content":"我的地盘听我的"  } 

修改文档document

请求url:

POST localhost:9200/blog1/article/1 

请求体:

{  "id":1,  "title":"【修改】ElasticSearch是一个基于Lucene的搜索服务器",  "content":"【修改】我的地盘听我的。"  } 

删除文档document

请求url:

DELETE localhost:9200/blog1/article/1 

相关内容

热门资讯

透视有挂!德普之星私人局辅助器... 透视有挂!德普之星私人局辅助器,德普之星怎么开辅助,专业教程(有挂黑科技)1.德普之星私人局辅助器 ...
透视最新!wejoker开挂(... 透视最新!wejoker开挂(透视)确实存在有挂(教你教程)wejoker开挂辅助器中分为三种模型:...
透视神器!aapoker辅助器... 透视神器!aapoker辅助器怎么用(透视)透视软件(其实是有挂)1、完成aapoker辅助器怎么用...
透视游戏!德普之星辅助工具如何... 透视游戏!德普之星辅助工具如何打开,德普之星私人局透视,高科技教程(有挂攻略)是一款可以让一直输的玩...
透视黑科技!wepoker私人... 透视黑科技!wepoker私人局有透视吗(透视)其实是有挂(安装教程);1、wepoker私人局有透...
透视软件!aapoker破解侠... 透视软件!aapoker破解侠是真的吗(透视)可以提高中牌率(其实存在有挂)1、完成aapoker破...
透视透视!德普之星辅助工具如何... 透视透视!德普之星辅助工具如何打开,德扑之心免费透视,必胜教程(有挂细节)是一款可以让一直输的玩家,...
透视最新!wepoker透视有... 透视最新!wepoker透视有用吗(透视)本来真的有挂(可靠教程);1)wepoker透视有用吗辅助...
透视规律!aapoker ai... 透视规律!aapoker ai插件(透视)辅助(果然有挂)1)aapoker ai插件辅助挂:进一步...
透视有挂!德普之星私人局透视,... 透视有挂!德普之星私人局透视,德普之星有辅助软件吗,教你攻略(有挂解说)1、超多福利:超高返利,海量...