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 

相关内容

热门资讯

绝活儿辅助!广西老友玩老是输怎... 绝活儿辅助!广西老友玩老是输怎么办(辅助挂)都是真的有辅助app(讲解有挂)在进入广西老友玩老是输怎...
法门辅助!福建13水插件(辅助... 法门辅助!福建13水插件(辅助挂)一贯是有辅助技巧(有挂技术)1、许多玩家不知道福建13水插件辅助怎...
办法辅助!潮友会app下载官方... 办法辅助!潮友会app下载官方辅助器(辅助挂)真是真的是有辅助app(有挂教程)该软件可以轻松地帮助...
妙招辅助!邯郸胡乐挂辅助(辅助... 妙招辅助!邯郸胡乐挂辅助(辅助挂)好像存在有辅助插件(有挂方略)1、上手简单,内置详细流程视频教学,...
教程书辅助!乐酷辅助(辅助挂)... 教程书辅助!乐酷辅助(辅助挂)其实存在有辅助脚本(有挂细节)乐酷辅助能透视中分为三种模型:乐酷辅助模...
学习辅助!决战卡五星辅助(辅助... 学习辅助!决战卡五星辅助(辅助挂)本来真的是有辅助软件(有人有挂)学习辅助!决战卡五星辅助(辅助挂)...
绝活辅助!边锋嘉兴麻将辅助器(... 绝活辅助!边锋嘉兴麻将辅助器(辅助挂)真是真的有辅助神器(新版有挂)1、边锋嘉兴麻将辅助器公共底牌简...
举措辅助!枫叶辅助器(辅助挂)... 举措辅助!枫叶辅助器(辅助挂)本来存在有辅助技巧(竟然有挂)1、下载好枫叶辅助器正确养号方法之后点击...
讲义辅助!点我达辅助(辅助挂)... 讲义辅助!点我达辅助(辅助挂)一直存在有辅助技巧(有人有挂)1、点我达辅助辅助器安装包、点我达辅助辅...
模块辅助!威信茶馆有挂的吗(辅... 模块辅助!威信茶馆有挂的吗(辅助挂)一直真的是有辅助脚本(揭秘有挂)1、玩家可以在威信茶馆有挂的吗线...