iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 27
1
Elastic Stack on Cloud

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

【少女人妻的30天Elastic】Day 27 : App Search_API 介紹與應用_Search Settings

  • 分享至 

  • xImage
  •  

Aloha!又是我少女人妻 Uerica!這個連假又過了一場奇幻旅程,交了兩個好朋友,心得是原來我們都很少真誠地訴說自己的感受,但人與人要拉近彼此的距離,除了真誠與真心敞開,別無他法了阿~

Search Settings

搜尋設定就是利用 API 的方式查詢與更改與重設字詞 Weights 、 Boosts 狀態,以及設定與定義 raw 、 snippet 回傳字元。

Show Settings

GET 請求顯示 Engine 中資料欄位的 Weights 與 Boosts 的狀態

GET /api/as/v1/engines/{ENGINE_NAME}/search_settings

需用 private key

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/search_settings' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d ''

Response

{
    "search_fields": {
        "area": {
            "weight": 2
        },
        "action_rule": {
            "weight": 1
        },
        "place_name": {
            "weight": 3
        },
        "note": {
            "weight": 1
        },
        "address": {
            "weight": 1
        },
        "city": {
            "weight": 1
        },
        "bh": {
            "weight": 1
        },
        "url": {
            "weight": 1
        },
        "phone": {
            "weight": 1
        },
        "stay_fee": {
            "weight": 1
        },
        "place_type": {
            "weight": 1
        },
        "place_desc": {
            "weight": 1
        },
        "place_facility": {
            "weight": 1
        },
        "close": {
            "weight": 1
        },
        "open": {
            "weight": 1
        },
        "lat": {
            "weight": 1
        },
        "id": {
            "weight": 1
        }
    },
    "result_fields": {
        "area": {
            "raw": {}
        },
        "place_name": {
            "raw": {}
        },
        "note": {
            "raw": {}
        },
        "id": {
            "raw": {}
        },
        "phone": {
            "raw": {}
        },
        "place_desc": {
            "raw": {}
        }
    },
    "boosts": {}
}

Update Settings

PUT 更新 Engine 中資料欄位的 Weights 與 Boosts 的狀態

PUT /api/as/v1/engines/{ENGINE_NAME}/search_settings
{
    "search_fields": {
        "area": {
            "weight": 4
        },
        "action_rule": {
            "weight": 1
        },
        "place_name": {
            "weight": 5
        },
        "note": {
            "weight": 1
        },
        "address": {
            "weight": 1
        },
        "city": {
            "weight": 4
        },
        "bh": {
            "weight": 1
        },
        "url": {
            "weight": 1
        },
        "phone": {
            "weight": 1
        },
        "stay_fee": {
            "weight": 1
        },
        "place_type": {
            "weight": 3
        },
        "place_desc": {
            "weight": 2
        },
        "place_facility": {
            "weight": 5
        },
        "close": {
            "weight": 1
        },
        "open": {
            "weight": 1
        },
        "lat": {
            "weight": 1
        },
        "id": {
            "weight": 1
        }
    },
    "result_fields": {
        "area": {
            "raw": {}
        },
        "place_name": {
            "raw": {}
        },
        "note": {
            "raw": {}
        },
        "id": {
            "raw": {}
        },
        "phone": {
            "raw": {}
        },
        "place_desc": {
            "snippet": {
            "size": 20,
            "fallback": true
        }
        }
    },
    "boosts": {
            "place_type": [
            {   
                "type": "value",
                "factor": 9.5,
                "value": [
                "true"
            ]
        }
        ]
    }
}

Reset Setting

POST 重設 Engine 中資料欄位的 Weights 與 Boosts 的狀態

POST /api/as/v1/engines/{ENGINE_NAME}/search_settings/reset
curl -X POST '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/search_settings/reset' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d ''

感謝各位閱讀,祝福大家都跟身邊的人越來越親近 :)


上一篇
【少女人妻的30天Elastic】Day 26 : App Search_API 介紹與應用_Search Fields (Weights) Search, Tags
下一篇
【少女人妻的30天Elastic】Day 28 : App Search_API 介紹與應用_Analytics
系列文
少女人妻的30天Elastic30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言