Example of mapping mapping configuration in Elasticsearch
For example, to build a Chinese news information search engine, the news has "title", "Content", "Author", "Type", "Release Time" of the five fields;
We want to provide "title and content Search", "sort", "highlight", "Statistics", "filter" and other basic functions.
ES provides SMARTCN's Chinese word breaker, and it is recommended to use the IK word breaker plugin for testing.
The properties in the content correspond to the contents of the mapping, inside 5 fields.
Type indicates the field type, content, Title field to be participle and highlight so set the word breaker and turn on Term_vector.
{
"News": {
"Properties": {
"Content": {#内容
' Type ': ' String ', #字段类型
"Store": "No", #是否存储
"Term_vector": "With_positions_offsets", #开启向量, for highlighting
"Index_analyzer": "Ik", #索引时分词器
"Search_analyzer": "Ik" #搜索时分词器
},
"title": {
' Type ': ' String ',
"Store": "No",
"Term_vector": "With_positions_offsets",
"Index_analyzer": "Ik",
"Search_analyzer": "Ik",
"Boost": 5
},
"Author": {
' Type ': ' String ',
"Index": "Not_analyzed" #该字段不分词
},
"Publish_date": {
"Type": "Date",
"Format": "Yyyy/mm/dd",
"Index": "Not_analyzed" #该字段不分词
},
"category": {
' Type ': ' String ',
"Index": "Not_analyzed" #该字段不分词
}
}
}
}
Query Example: Content consists of several parts:
Page: from/size, Field: Fields, sort, query: queries, filtering: Filter, highlighting: Highlight, Statistics: facets
{
"From": 0,
"Size": 10,
"Fields": [
"Title",
"Content",
"Publish_date",
"Category",
"Author"
],
"Sort": [
{
"Publish_date": {
"Order": "ASC"
}
},
"_score"
],
"Query": {
"BOOL": {
"Should": [
{
"term": {
"title": "China"
}
},
{
"term": {
"Content": "China"
}
}
]
}
},
"Filter": {
"Range": {
"Publish_date": {
"From": "2010/07/01",
"To": "2010/07/21",
"Include_lower": true,
"Include_upper": false
}
}
},
"Highlight": {
"Pre_tags": [
"<tag1>",
"<tag2>"
],
"Post_tags": [
"</tag1>",
"</tag2>"
],
"Fields": {
"title": {},
"Content": {}
}
},
"Facets": {
"Cate": {
"Terms": {
"Field": "Category"
}
}
}
}
The result contains several parts that are needed.
It should be noted that facet statistics is the result of the hit statistics, filter is the result of filtering, filter does not affect the facet, if you want to count the filter out of the use of the filter facet.
Mapping mapping configuration and query in Elasticsearch typical case