Mapping mapping configuration and query in Elasticsearch typical case

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.