1. 程式人生 > >ElasticSearch最佳入門實踐(四十一)query string 的分詞以及 mapping 引入案例遺留問題的大揭祕

ElasticSearch最佳入門實踐(四十一)query string 的分詞以及 mapping 引入案例遺留問題的大揭祕

1、query string分詞

query string必須以和index建立時相同的analyzer進行分詞

query string對exact value和full text的區別對待
date:exact value
_all:full text
比如我們有一個document,其中有一個field,包含的value是:hello you and me,建立倒排索引
我們要搜尋這個document對應的index,搜尋文字是hell me,這個搜尋文字就是query string
query string,預設情況下,es會使用它對應的field建立倒排索引時相同的分詞器去進行分詞,分詞和normalization,只有這樣,才能實現正確的搜尋
我們建立倒排索引的時候,將dogs --> dog,結果你搜索的時候,還是一個dogs,那不就搜尋不到了嗎?所以搜尋的時候,那個dogs也必須變成dog才行。才能搜尋到。
知識點:不同型別的field,可能有的就是full text,有的就是exact value
post_date,date:exact value
_all:full text,分詞,normalization

2、mapping引入案例遺留問題大揭祕

GET /website/article/_search?q=2017
搜尋的是_all field,document所有的field都會拼接成一個大串,進行分詞
2017-01-02 my second article this is my second article in this website 11400
在這裡插入圖片描述

doc1 doc2 doc3
2017 * * *
01 *
02 *
03 *

_all,2017,自然會搜尋到3個docuemnt
GET /website/article/_search?q=2017-01-01
_all,2017-01-01,query string會用跟建立倒排索引一樣的分詞器去進行分詞
2017
01
01

GET /website/article/_search?q=post_date:2017-01-02
date,會作為exact value去建立索引

doc1 doc2 doc3
2017-01-01 *
2017-01-02 *
2017-01-03 *

所以post_date:2017-01-01,2017-01-01,doc1一條document

GET /website/article/_search?q=post_date:2017
因為是es 5.2以後做的一個優化

3、測試分詞器

GET /_analyze{"analyzer": "standard","text": "Text to analyze"}