ES highlight測試

來源:互聯網
上載者:User

標籤:

Lucene提供3種高亮功能:highlighter, fast-vector-highlighter or postings-highlighter.
  • highlighter: 最基本的、預設的高亮器。需要對查詢的_source進行二次Reanalyzed,速度在3種高亮器裡最慢,但不需要額外儲存index。
  • postings-highighlighter: setting中需要配置"index_options" : "offsets",postings優缺點。速度中等,但是在phrase(短語查詢) query結合的查詢中,會把查詢短語的每個詞單獨高亮顯示。
  • fast-vector-highligh: setting中需要配置"term_vector" : "with_positions_offsets",速度最快,但是佔用儲存空間最大。典型空間換速度。
測試
  • mapping

    1. curl -XPUT ‘localhost:9200/hl-test‘ -d ‘{
    2. "settings": {
    3. "index": {
    4. "number_of_shards": 2,
    5. "number_of_replicas": 0
    6. }
    7. },
    8. "mappings": {
    9. "tm": {
    10. "properties": {
    11. "content1": {
    12. "type": "string",
    13. "analyzer" : "default",
    14. "store": "yes",
    15. "term_vector" : "with_positions_offsets"
    16. },
    17. "content2": {
    18. "type": "string",
    19. "analyzer" : "default",
    20. "store": "yes",
    21. "index_options" : "offsets"
    22. },
    23. "content3": {
    24. "type": "string",
    25. "store": "yes",
    26. "analyzer" : "default"
    27. },
    28. "content4": {
    29. "type": "string",
    30. "store": "yes",
    31. "index": "not_analyzed"
    32. }
    33. }
    34. }
    35. }
    36. }‘

    note

    offsets
    Store docs, freqs, positions, and the start and end character offsets of each term in the original string. This information is used by the postings >highlighter but is disabled by default.
    來源: https://www.elastic.co/guide/en/elasticsearch/guide/current/stopwords-phrases.html#index-options

  • 測試資料
    curl -XPUT ‘http://localhost:9200/hl-test/tm/1‘ -d ‘{ "content1": "In the above case, the content field will be highlighted for each search hit (there will be another element in each search hit, called highlight, which includes the highlighted fields and the highlighted fragments)."}‘

  • Query DSL
    1. {
    2. "query": {
    3. "term": {
    4. "content1": "the"
    5. }
    6. },
    7. "highlight": {
    8. "pre_tags": [
    9. "<tag1>"
    10. ],
    11. "post_tags": [
    12. "</tag1>"
    13. ],
    14. "fields": {
    15. "content1": {
    16. "type": "fvh",
    17. "fragment_size": 30,
    18. "number_of_fragments": 1,
    19. "force_source": true,
    20. "order": "score",
    21. "fragment_offset": 3,
    22. "no_match_size": 2
    23. },
    24. "content2": {
    25. "fragment_size": 250,
    26. "number_of_fragments": 0
    27. },
    28. "content3": {
    29. "fragment_size": 250,
    30. "number_of_fragments": 3,
    31. "force_source": true
    32. }
    33. }
    34. }
    35. }


來自為知筆記(Wiz)

ES highlight測試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.