iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 26
2
Elastic Stack on Cloud

少女人妻的30天Elastic系列 第 26

【少女人妻的30天Elastic】Day 26 : App Search_API 介紹與應用_Search Fields (Weights) Search, Tags

  • 分享至 

  • twitterImage
  •  

Aloha!又是我少女人妻 Uerica!連假的時候一定要好好休息,千萬不能勉強工作,不然會變成連假勞工喔

Search, Search Fields (Weights)

Search_Fields 可分別給予搜尋結果欄位不同的權重分數,使每筆資料的重要程度不同來影響搜尋排序。Search_Fields 會限制搜尋欄位,且僅 text 類型欄位可用。

  • query (required) : 查詢特定字詞
  • search_fields (required) : 定義需設定search_fields的查詢字詞
  • fields (optional) : 欄位需存在資料中,且是 text 類型
  • weight (optional) : 權重設定,介於 1 (輕) - 10 (重) 之間

定義search_fields中的欄位並給予權重分數

curl -X POST '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-xxxxxxxxxx' \
-d '{
  "search_fields": {
    "title": {
      "weight": 10
    },
    "description": {
      "weight": 5
    },
    "states": {
      "weight": 3
    }
  },
  "query": "everglade"
}'

Search Tags

查詢並送出帶有 analytics 參數的 tag ,但添加後便無法刪除標籤,可用 array 方式寫入參數

curl -X POST '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-xxxxxxxxxx' \
-d '{
  "query": "花蓮",
  "analytics": {
    "tags": [
      "web",
      "mobile"
    ]
  }
}'

好啦~感謝大家閱讀,明天見拉掰掰~~


上一篇
【少女人妻的30天Elastic】Day 25 : Elastic App Search_Search, Result Fields (Highlights) API
下一篇
【少女人妻的30天Elastic】Day 27 : App Search_API 介紹與應用_Search Settings
系列文
少女人妻的30天Elastic30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言