当前位置:网站首页>Introduction to mapping in ES
Introduction to mapping in ES
2022-06-26 07:08:00 【Talk to me】
Default mapping
elasticsearch( hereinafter referred to as ES) No mode (schema) Of , When we execute the following command :
curl -XPUT http://localhost:9200/test/item/1 -d '{"name":"bob", "description": "A Pretty cool guy."}'ES Can be very smart to identify "name" and "description" The type of field is string, ES The following... Will be created by default mapping:
mappings: {
item: {
properties: {
description: {
type: string
}
name: {
type: string
}
}
}
}What is? mapping
ES Of mapping It's very similar to data types in static languages : Declare a variable as int Variable of type , In the future, this variable can only store int Data of type . alike , One number Type of mapping Fields can only store number Data of type .
Compared to the data type of the language ,mapping There are other implications ,mapping Not only tell ES One field What kind of value is in , It also tells ES How to index data and whether data can be searched .
notes : When your query does not return the corresponding data , Yours mapping It's very likely that there's a problem . When you're not sure , Check your... Directly mapping.
analyse mapping
One mapping By one or more analyzer form , One analyzer By one or more filter Composed of . When ES When Indexing Documents , It passes the contents of the field to the corresponding analyzer,analyzer And then pass it on to their filters.
filter The function of is easy to understand : One filter Is a method of converting data , Enter a string , This method returns another string , For example, a method to convert a string to lowercase is filter A good example .
One analyzer Arranged in a sequence filter form , The process of performing the analysis is one by one filter One filter In turn, calls , ES Store and index the final results .
In conclusion , mapping The function of is to execute a series of instructions to convert the input data into searchable index items .
Default analyzer
Back to our example , ES guess description The fields are string type , By default, you create a string Type of mapping, It uses the default global analyzer, default analyzer yes standard analyzer, This standard analyzer There are three filter:token filter, lowercase filter and stop token filter.
We can type... When we make a query _analyze Keyword view analysis process . Use the following instructions to view description Field conversion process :
curl -X GET "http://localhost:9200/test/_analyze?analyzer=standard&pretty=true" -d "A Pretty cool guy."
{
"tokens" : [ {
"token" : "pretty",
"start_offset" : 2,
"end_offset" : 8,
"type" : "<ALPHANUM>",
"position" : 2
}, {
"token" : "cool",
"start_offset" : 9,
"end_offset" : 13,
"type" : "<ALPHANUM>",
"position" : 3
}, {
"token" : "guy",
"start_offset" : 14,
"end_offset" : 17,
"type" : "<ALPHANUM>",
"position" : 4
} ]You can see , our description The value of the field is converted to [pretty], [cool], [guy], Capitalized during conversion A, Punctuation marks are filter Filtered out , Pretty It is also converted to all lowercase pretty, Here's the important thing , Even if ES When storing data, the complete data is still stored , But these three words are the only keywords that can search this data , All the others were abandoned .
Look at the words a To search for results :
$ curl -X GET "http://localhost:9200/test/_search?pretty=true" -d '{
"query" : {
"text" : { "description": "a" }
}
}'
{
"took" : 29,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
text Type of search uses the same analysis as the previously inserted data in the query process / Filtration system , So we type "a",mapping There will be no return , Because of the word “a” It won't be ES Storage and indexing . In turn, , If we use words "cool" To search :
curl -X GET "http://localhost:9200/test/_search?pretty=true" -d '{
"query" : {
"text" : { "description": "cool" }
}
}'
{
"took" : 29,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.15342641,
"hits" : [ {
"_index" : "test",
"_type" : "item",
"_id" : "1",
"_score" : 0.15342641, "_source" : {"name":"zach", "description": "A pretty cool guy"}
} ]
}
}Now you can get the right result , This is an accepted simple example , But it describes ES How it works , Don't put the mapping Think of it as a data type , Think of it as a set of instructions to search for data . If you don't want characters "a" Be deleted , You need to modify your analyzer.
边栏推荐
- Pytorch builds CNN LSTM hybrid model to realize multivariable and multi step time series forecasting (load forecasting)
- STM32F1与STM32CubeIDE编程实例-热敏传感器驱动
- 网络io,磁盘io
- China's Ni MH battery industry development overview analysis and investment trend forecast report 2022 Edition
- Solution of garbled code in sparkshell deletion key of SecureCRT
- Liujinhai, chief architect of zhongang Mining: according to the analysis of fluorite supply and demand, it is estimated that the fluorine coating market has great potential
- Mysql操作数据库
- How can I find the completely deleted photos in Apple mobile phone?
- If you meet a female driver who drives didi as an amateur, you can earn 500 yuan a day!
- . Net 20th anniversary! Microsoft sends a document to celebrate
猜你喜欢

Liquid crystal texture diagram of purple solid mm-tpp-10c methacrylic acid decanoxy tetraphenyl porphyrin and mm-tpp-12c methacrylic acid dodecanoxy tetraphenyl porphyrin - Qi Yue display

Guide to "avoid dismissal during probation period"

Zraqnhydae

3,3 '- di (3,4-dicarboxyphenoxy) -4,4' - diphenylethynylbiphenyldianhydride (bpebpda) / porphyrin 2dcofs (H2P COF, ZNP COF and cup COF) supplied by Qiyue

How to publish function computing (FC) through cloud effect

基于sanic的服务使用celery完成动态修改定时任务

13. Mismatch simulation of power synthesis for ads usage recording

Service interface test guide

【图像融合】基于耦合特征学习的多模式医学图像融合附matlab代码

Iron / zinc / copper / platinum metal complexes such as 5,10,15,20-tetra (4-hydroxyphenyl) porphyrin (THPP) / (thppfe) / (thppzn) / (thppcu) / (thpppt) - Qiyue R & D
随机推荐
[feature extraction] feature selection of target recognition information based on sparse PCA with Matlab source code
[yolov4] matlab simulation of network target detection based on yolov4 deep learning
Analyse d'un problème classique
5,10,15,20-tetra (4-bromophenyl) porphyrin (h2tppbr4) /5.2.15,10,15,20-tetra [4-[(3-aminophenyl) ethynyl] phenyl] porphyrin (tapepp) Qiyue porphyrin reagent
【图像检测】基于形态学实现图像目标尺寸测量系统附matlab代码
SQL query statement
What is data mining?
Redis系列——redis启动,客户端day1-2
基于sanic的服务使用celery完成动态修改定时任务
Solve the problem of transparency at the bottom of dialog
二叉树中和为某一值的路径(一)(二)(三)(剑指offer)
SQL
STM32F1与STM32CubeIDE编程实例-热敏传感器驱动
分析 NFT 项目的 5 个指标
NumPy学习挑战第五关-创建数组
[image fusion] MRI-CT image fusion based on gradient energy, local energy and PCA fusion rules with matlab code
Liquid crystal texture diagram of purple solid mm-tpp-10c methacrylic acid decanoxy tetraphenyl porphyrin and mm-tpp-12c methacrylic acid dodecanoxy tetraphenyl porphyrin - Qi Yue display
【路径规划】基于改进人工势场实现机器人路径规划附matlab代码
一芯实现喷雾|WS2812驱动|按键触摸|LED显示|语音播报芯片等功能,简化加湿器产品设计
Meso tetra (4-bromophenyl) porphyrin (tbpp); 5,10,15,20-tetra (4-methoxy-3-sulfonylphenyl) porphyrin [t (4-mop) ps4] supplied by Qiyue