日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

elasticsearch分词聚合查询demo

發布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 elasticsearch分词聚合查询demo 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

我們在通過elasticsearch查詢text類型的字段時,我們使用aggs進行聚合某個text類型field。這時elasticsearch會自動進行分詞將分詞后的結果進行聚合。獲取每一個分詞出現在文檔的文檔個數。注意:是文檔的次數不是文檔中分詞出現的次數,也就是說即便某個詞在某個文檔中出現了多次,但是只記錄這個詞的doc_count次數為1.

添加一個可分詞的text字段模板:

需要添加 analyzer 和 fielddata兩個屬性

[java]?view plain?copy

  • "allContent":?{??
  • ???????????????"type":?"text",??
  • ???????????????"analyzer":?"ik_smart",??
  • ???????????????"fielddata":?true??
  • ??????????????}??
  • ?

    ?

    查詢語句例子:

    ?

    [java]?view plain?copy

  • GET?voice*/_search??
  • {??
  • ??"_source":?"{transData.allContent}",??
  • ??"query":?{},??
  • ??"aggs":?{??
  • ????"hotword":?{??
  • ??????"terms":?{??
  • ????????"field":?"transData.allContent",??
  • ????????"size":?10,??
  • ????????"order":?{??
  • ??????????"_count":?"desc"??
  • ????????}??
  • ??????}??
  • ????}??
  • ??},??
  • ??"size":?0??
  • }??

  • 這里的size:0控制的是結果中hits展示的個數。

    ?

    查詢結果例子:

    ?

    [java]?view plain?copy

  • {??
  • ??"took":?0,??
  • ??"timed_out":?false,??
  • ??"_shards":?{??
  • ????"total":?5,??
  • ????"successful":?5,??
  • ????"failed":?0??
  • ??},??
  • ??"hits":?{??
  • ????"total":?1,??
  • ????"max_score":?0,??
  • ????"hits":?[]??
  • ??},??
  • ??"aggregations":?{??
  • ????"hotword":?{??
  • ??????"doc_count_error_upper_bound":?1,??
  • ??????"sum_other_doc_count":?314,??
  • ??????"buckets":?[??
  • ????????{??
  • ??????????"key":?"ok",??
  • ??????????"doc_count":?119??
  • ????????},??
  • ????????{??
  • ??????????"key":?"一",??
  • ??????????"doc_count":?123??
  • ????????},??
  • ????????{??
  • ??????????"key":?"一下",??
  • ??????????"doc_count":?114??
  • ????????},??
  • ????????{??
  • ??????????"key":?"一個",??
  • ??????????"doc_count":?91??
  • ????????},??
  • ????????{??
  • ??????????"key":?"一個月",??
  • ??????????"doc_count":?52??
  • ????????},??
  • ????????{??
  • ??????????"key":?"一些",??
  • ??????????"doc_count":?23??
  • ????????},??
  • ????????{??
  • ??????????"key":?"一包",??
  • ??????????"doc_count":?13??
  • ????????},??
  • ????????{??
  • ??????????"key":?"一塊",??
  • ??????????"doc_count":?11??
  • ????????},??
  • ????????{??
  • ??????????"key":?"一天",??
  • ??????????"doc_count":?4??
  • ????????},??
  • ????????{??
  • ??????????"key":?"一定",??
  • ??????????"doc_count":?2??
  • ????????}??
  • ??????]??
  • ????}??
  • ??}??
  • }??
  • 轉載于:https://my.oschina.net/xiaominmin/blog/1785461

    總結

    以上是生活随笔為你收集整理的elasticsearch分词聚合查询demo的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。