ElasticSearch教程——自定義分詞器(轉學習使用)

一、分詞器

Elasticsearch中,內置了很多分詞器(analyzers),例如standard(標準分詞器)、english(英文分詞)和chinese(中文分詞),默認是standard.

standard tokenizer:以單詞邊界進行切分
standard token filter:什么都不做
lowercase token filter:將所有字母轉換為小寫
stop token filer(默認被禁用):移除停用詞,比如a the it等等

?

二、修改分詞器設置

啟用english,停用詞token filter

PUT /my_index
{"settings": {"analysis": {"analyzer": {"es_std":{"type":"standard","stopwords":"_english_"}}}}
}

三、標準分詞測試代碼

GET /my_index/_analyze
{"analyzer": "standard","text":"a dog is in the house"
}

結果:

{"tokens": [{"token": "a","start_offset": 0,"end_offset": 1,"type": "<ALPHANUM>","position": 0},{"token": "dog","start_offset": 2,"end_offset": 5,"type": "<ALPHANUM>","position": 1},{"token": "is","start_offset": 6,"end_offset": 8,"type": "<ALPHANUM>","position": 2},{"token": "in","start_offset": 9,"end_offset": 11,"type": "<ALPHANUM>","position": 3},{"token": "the","start_offset": 12,"end_offset": 15,"type": "<ALPHANUM>","position": 4},{"token": "house","start_offset": 16,"end_offset": 21,"type": "<ALPHANUM>","position": 5}]
}

四、設置的英文分詞測試代碼

GET /my_index/_analyze
{"analyzer": "es_std","text":"a dog is in the house"}

結果:

{"tokens": [{"token": "dog","start_offset": 2,"end_offset": 5,"type": "<ALPHANUM>","position": 1},{"token": "house","start_offset": 16,"end_offset": 21,"type": "<ALPHANUM>","position": 5}]
}

五、自定義分詞器

PUT /my_index
{"settings": {"analysis": {"char_filter": {"&_to_and": {"type": "mapping","mappings": ["&=> and"]}},"filter": {"my_stopwords": {"type": "stop","stopwords": ["the", "a"]}},"analyzer": {"my_analyzer": {"type": "custom","char_filter": ["html_strip", "&_to_and"],"tokenizer": "standard","filter": ["lowercase", "my_stopwords"]}}}}
}

測試:

GET /my_index/_analyze
{"text": "tom&jerry are a friend in the house, <a>, HAHA!!","analyzer": "my_analyzer"
}

結果:

{"tokens": [{"token": "tomandjerry","start_offset": 0,"end_offset": 9,"type": "<ALPHANUM>","position": 0},{"token": "are","start_offset": 10,"end_offset": 13,"type": "<ALPHANUM>","position": 1},{"token": "friend","start_offset": 16,"end_offset": 22,"type": "<ALPHANUM>","position": 3},{"token": "in","start_offset": 23,"end_offset": 25,"type": "<ALPHANUM>","position": 4},{"token": "house","start_offset": 30,"end_offset": 35,"type": "<ALPHANUM>","position": 6},{"token": "haha","start_offset": 42,"end_offset": 46,"type": "<ALPHANUM>","position": 7}]
}

六、type中的使用

PUT /my_index/_mapping/my_type
{"properties": {"content": {"type": "text","analyzer": "my_analyzer"}}
}

?

轉載于:https://www.cnblogs.com/yfb918/p/10718712.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/277927.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/277927.shtml
英文地址,請注明出處:http://en.pswp.cn/news/277927.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

使用Azure Serverless來開發Teams App

Azure Function可以說比較早期的一個serverless服務&#xff0c;隨著這些年云服務的大行其道&#xff0c;Serverless在概念越來越火&#xff0c;什么叫serverless&#xff1f; Serverless computing (or serverless for short), is an execution model where the cloud provide…

Angular之RouterModule的forRoot與forChild

Angular 提供了一種方式來把服務提供商從模塊中分離出來&#xff0c;以便模塊既可以帶著 providers 被根模塊導入&#xff0c;也可以不帶 providers 被子模塊導入。 區別&#xff1a; forRoot creates a module that contains all the directives, the given routes, and the r…

關于 someone could be eavesdropping on you right now (man-in-the-middle attack) ssh的解決辦法

關于 someone could be eavesdropping on you right now (man-in-the-middle attack) ssh的解決辦法 記錄工作中遇到的問題 someone could be eavesdropping on you right now (man-in-the-middle attack) ssh  由于遠程機器或者重組或者更新了ssh server導致本地記錄的驗證信…

使用AzureFunction開發最簡單的Teams Outgoing Webhook

上篇文章講了teams app的serverless架構&#xff0c;這篇主要講如何真正使用Azure Function來開發一個最最簡單的Teams Outgoing Webhook。 我們先登入azure的portal&#xff0c;創建一個azure function。我這里創建了一個名字叫outgoing-webhook的azure function。完成后如下…

Java 基礎 之 標識符

www.verejava.com/?id1699254… /* 標識符的命名規則: 1. 是以字母&#xff0c;數字&#xff0c;下滑線_和美元符號$ 組成 2. 不能以數字開頭 3. 區分大小寫 4. 不能是java的保留關鍵字 5. 最好是見名思意 */ public class Identifier {public static void main(String[] args…

Ubuntu宿主機與VMware中其他系統虛擬機的互通

Ubuntu做宿主機&#xff0c;VMware中創建Windows10&#xff0c;并且通過三種模式實現兩系統互通&#xff0c;其實并非是件難事。在有線網卡未接網線的環境下&#xff0c;關閉兩系統防火墻&#xff0c;基本遵從下文便可實現。 轉載&#xff1a;https://note.youdao.com/ynotesha…

使用Azure輕松實現Teams App的全球合規性

我在之前的一篇博客里面講了合規性對于我們Teams app是非常重要的&#xff0c;因為office365平臺就是面向全世界用戶的&#xff0c;我們開發的teams app一旦發布后&#xff0c;立刻就會有各國各地區的用戶來進行安裝使用&#xff0c;所以符合用戶所在地區的要求是非常重要的。 …

【php復習之】php創建數組的幾種方式

1、array()函數 1.1無key值 $arrarray(1,2,3,4); 1.2鍵值對 $arrarray( name>myj,age>18,phone>1888888888);1.3空數組 $arrarray(); 2、compact()函數 compact函數可以把變量轉換為數組。 $a aaa;$b bbb;$c ccc;$arr3 compact(a,b,c);輸出&#xff1a;{"a&q…

ADC知識(2)——直流參數(輸入電壓參考,參考電流輸入,積分非線性誤差,差分非線性誤差)...

目錄 四、 輸入參考電壓范圍 五、 參考電流 六、 非線性問題 差分非線性誤差 積分非線性 四、 輸入參考電壓范圍 大多數數據手冊中&#xff0c;將它定義為一個特定的參考電壓值&#xff0c;通常這個電壓作為 此轉換器最常用的參考電壓。在參考輸入電壓…

LuckyDraw app使用CosmosDB的成本分析

我在以前的博客里說過我的LuckyDraw app在數據存儲方面使用的是 Azure Table Storage&#xff0c;當時選擇這個的原因是成本考慮&#xff0c;因為它實在是便宜&#xff0c;對于我這種個人開發維護的免費的teams app來說&#xff0c;成本是一個很重要的考量點。 當然&#xff0…

React 重溫之 組件生命周期

生命周期 任何事物都不會憑空產生&#xff0c;也不會無故消亡。一個事物從產生到消亡經理的各個階段&#xff0c;我們稱之為 生命周期。 具體到我們的前端組件上來&#xff0c;一個組件的生命周期可以大體分為創建、更新、銷毀這個三個階段。 本文主要介紹React 的組件生命周期…

遷移聊天記錄到Teams

有一些朋友問我teams是否支持將其他平臺/系統里的聊天記錄遷移某個channel里&#xff0c;答案是肯定的&#xff0c;teams團隊在去年年中的時候就提供了這個功能。這個功能是通過graph api來完成的&#xff0c;我們今天就來看看如何遷移聊天記錄到teams里。 首先&#xff0c;我…

leetcode-191-Number of 1 Bits

題目描述&#xff1a; Write a function that takes an unsigned integer and returns the number of 1 bits it has (also known as the Hamming weight). Example 1: Input: 11 Output: 3 Explanation: Integer 11 has binary representation 000000000000000000000000000010…

androidsdk里的android.bat和uiautomatorview.bat啟動就閃退問題

進入D:\androidsdk\tools文件夾&#xff1a; 使用編輯文件工具&#xff1a; rem Check we have a valid Java.exe in the path.set java_execall lib\find_java.bat 替換成下列代碼&#xff1a; rem Check we have a valid Java.exe in the path.set java_exeC:\Program Files\…

10 個優質的 Laravel 擴展推薦

這里有 10 個用來搭建 Laravel 應用的包 為何會創建這個包的列表&#xff1f;因為我是一個「比較懶」的開發者&#xff0c;在臉書上是多個 Laravel 小組的成員。平日遇到最多的問題就是開發是需要用那些包。我很懶所以我不想每次都從頭開始搞這些東東。 為何此文沒有包括管理包…

Teams AppId, InstallationId 和 ExternalId 的區別

大家如果看teams的 graph api 開發文檔&#xff0c;可能會把 app id, installation id 和 external id 搞混&#xff0c;我自己一開始的時候就有點被搞暈了&#xff0c;再加上app manifest里面的 id 和 bot id&#xff0c;基本就徹底暈掉了。 那我們今天這篇文章就來講講這幾種…

osi參考模型(開放系統互連參考模型)

自互聯網誕生以來&#xff0c;隨著網絡飛速發展&#xff0c;用戶迫切要求能在不同體系結構的網絡空間交換信息&#xff0c;使得不同的網絡能夠互聯起來。 國際化標準組織&#xff08;International Organization for Standardization&#xff0c;即ISO&#xff09;從1977年開始…

Java:反射+泛型:獲取類型參數的實例

2019獨角獸企業重金招聘Python工程師標準>>> 場景描述&#xff1a; 我需要開發四個頁面&#xff0c;每個頁面都是只涉及增刪改查的基本邏輯。 最簡單的寫法&#xff1a; 創建四個接口A,B,C,D&#xff0c;每個接口中都聲明了增刪改查四個方法,完全一致 public Map<…

servlet(1)

servlet類分級&#xff1a; 1.ServletConfig接口類&#xff1a;理解為讀取servlet配置的類&#xff0c;里面有四個抽象方法如下&#xff1a; ①getServletName:獲取servlet在web.xml中的名字 ②getServletContext&#xff1a;獲取Servlet上下文&#xff0c;相當于web項目管理所…

如何在 Apple Silicon (M1) 上開發 Teams App

apple 在幾個月前發布了自家的芯片 M1&#xff0c;由于將多核cpu&#xff0c;多核gpu&#xff0c;神經網絡運算&#xff0c;內存和其他一切處理部件高度整合在一起&#xff0c;大大提高數據傳輸速度。發布后好評如潮&#xff0c;我也沒有忍住&#xff0c;入手了一臺最低配的mac…