Es field aliases when creating mapping

Source: Internet
Author: User

Es by default is the mapping of dynamically creating indexes and index types, but can be used when learning, and must be manually developed in production mapping! In production often encounter such a demand, want to use a field to statistics, and want to fuzzy query the field, the way to solve this requirement is to create an alias for this field!

The mapping structure is as follows:

1 {2"Settings" : {3"Index" : {4"Analysis" : {5"Filter" : {6"English_keywords" : {7"Type": "Keyword_marker",8"keywords" : [9"Topsec"Ten                         ] One                     }, A"English_stemmer" : { -"Type": "Stemmer", -"Language": "中文版" the                     }, -"English_possessive_stemmer" : { -"Type": "Stemmer", -"Language": "Possessive_english" +                     }, -"English_stop" : { +' type ': ' Stop ', A"Stopwords": "_english_" at                     } -                 }, -"Analyzer" : { -"Default" : { -"Tokenizer": "Keyword" -                     }, in"中文版" : { -"Type": "Custom", to"Filter" : [ +"Lowercase", -"English_stop" the                         ], *"Tokenizer": "Standard" $                     },Panax Notoginseng"Ik" : { -"Filter": ["lowercase"], the"Type": "Custom", +"Tokenizer": "Ik_max_word" A                     }, the"HTML" : { +"Filter" : [ -"Lowercase", $"English_stop" $                         ], -"Char_filter" : [ -"Html_strip" the                         ], -"Type": "Custom",Wuyi"Tokenizer": "Standard" the                     }, -"Lower" : { Wu"Filter": "Lowercase", -"Type": "Custom", About"Tokenizer": "Keyword" $                     } -                 } -             }, -"Number_of_shards": "1", A"Number_of_replicas": "0" +         } the     }, -"Mappings" : { $"Test" : { the"_all" : { the"Enabled":false the             }, the"Properties" : { -"Name" : { in"Type": "Keyword" the                 }, the"Age" : { About"Type": "Keyword", the"Fields" : { the"CN" : { the"Analyzer": "IK", +' Type ': ' Text ' -                         } the                     }Bayi                 }, the  the"Address" : { -' Type ': ' Text ' -                 } the             } the         } the     } the}

Field age "type": "keyword", do not participle, then from the individual name CN, it uses the IK word breaker for word breakers! Insert four piece of data

When you use the age field to count the data, you need to use the time-of-day and the full-match rule, the statement:

1 {2"Query": {3"BOOL": {4"Must": [5         {6"Term": {7"Age": "Xi er qi Zhong Guan cun Xi men, Haidian District, Peking City"8           }9         }Ten       ], One"Must_not": [], A"Should": [] -     } -   }, the"From": 0, -"Size": 10, -"Sort": [], -"Aggs": {} +}

Results:

It is problematic to use Age's participle age.cn to make statistics, and the result of running indicates that the alias of age is age.cn, and the query condition must match the result of the word breaker to the content of age.

1 {2"Query": {3"BOOL": {4"Must": [5         {6" Term": {7"age.cn": "Xi er qi Zhong Guan cun Xi men, Haidian District, Peking City"8           }9         }Ten       ], One"Must_not": [], A"Should": [] -     } -   }, the"From": 0, -"Size": 10, -"Sort": [], -"Aggs": {} +}

Results:

1 {2"Query": {3"BOOL": {4"Must": [5         {6" Term": {7"age.cn": "Beijing"8           }9         }Ten       ], One"Must_not": [], A"Should": [] -     } -   }, the"From": 0, -"Size": 10, -"Sort": [], -"Aggs": {} +}

Results:

If you use match to count the words will also have a problem, will be incorrect data also statistics, using match statistics will match the query conditions and content, according to the matching degree, score high description matching high, will be ranked above

1 {2"Query": {3"BOOL": {4"Must": [5         {6"Match": {7"age.cn": "Xi er qi Zhong Guan cun, Haidian District, Peking City"8           }9         }Ten       ], One"Must_not": [], A"Should": [] -     } -   }, the"From": 0, -"Size": 10, -"Sort": [], -"Aggs": {} +}

Results:

Here's the result of scoring by match

1 {2"Query": {3"BOOL": {4"Must": [5         {6"Match": {7"age.cn": "Beijing Changping District"8           }9         }Ten       ], One"Must_not": [], A"Should": [] -     } -   }, the"From": 0, -"Size": 10, -"Sort": [], -"Aggs": {} +}

Results:

Summary: Statistics on the use of term, no participle, full match; Fuzzy query with match, participle, not the full match!

If there are any shortcomings, please understand and criticize, I appreciate!!!!! Welcome message to discuss!!!

Es field aliases when creating mapping

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.