Elasticsearch 映射參數(shù)詳解 fields
Elasticsearch 映射參數(shù) fields
fields
處于不同的目的,通過不同的方法索引相同的字段通常非常有用。這也是多字段的目的。例如,一個字符串字段可以映射為text字段用于全文本搜索,也可以映射為keyword字段用于排序或聚合。
PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"city": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
}
note:city.raw字段是city字段的keyword版本。
GET my_index/_search
{
"query": {
"match": {
"city": "york"
}
},
"sort": {
"city.raw": "asc"
},
"aggs": {
"Cities": {
"terms": {
"field": "city.raw"
}
}
}
}
note:city字段用于全文本搜索。
note:city.raw用于排序與聚合。
多字段不能修改原始_source字段。
對于相同索引中具有相同名稱的字段,fields設置允許有不同的設置??梢允褂肞UT映射API將新的多字段添加到已存在的字段中。
帶有多個分析的多字段
多字段的另一個應用場景是使用不同的方法分析相同的字段以求獲得更好的相關性。
PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"text": {
"type": "text",
"fields": {
"english": {
"type": "text",
"analyzer": "english"
}
}
}
}
}
}
}
note:text.field字段使用english分析器。
elasticsearch注解實現(xiàn)fields
mapping效果:
"label": {
"type": "keyword",
"fields": {
"IKS": {
"type": "text",
"analyzer": "ikIndexAnalyzer"
}
}
}
@Column(name = "標簽")
@MultiField(
mainField = @Field(type = FieldType.Keyword),
otherFields = {
@InnerField(suffix = "IKS", type = FieldType.Text, analyzer = "ikIndexAnalyzer")
}
)
protected String label;
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
關于springboot中對sqlSessionFactoryBean的自定義
這篇文章主要介紹了springboot中對sqlSessionFactoryBean的自定義方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12
解決IDEA2021版compiler.automake.allow.when.app.running不存在的問題
很多文章介紹IntelliJ IDEA開啟熱部署功能都會寫到在IntelliJ IDEA中的注冊表中開啟compiler.automake.allow.when.app.running選項,此選項在IntelliJ IDEA 2021.2之后的版本遷移到高級設置中,下面看下設置方法2021-09-09
Maven?繼承父工程時的relativePath標簽詳細解析
這篇文章主要介紹了Maven?繼承父工程時的relativePath標簽解析,通過本文學習你需要注意子模塊想要用父模塊pom中的版本,請注意配置relativePath屬性,需要的朋友可以參考下2022-12-12
解決Spring Boot 多模塊注入訪問不到jar包中的Bean問題
這篇文章主要介紹了解決Spring Boot 多模塊注入訪問不到jar包中的Bean問題。具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09

