Module: Aliyun::Opensearch::ClientExt::Traffic::Behavior
- Included in:
- Aliyun::Opensearch::Client
- Defined in:
- lib/aliyun/opensearch/client_ext/traffic/behavior.rb
Overview
各种接口行为
Constant Summary collapse
- API_SEARCH =
'/v3/openapi/apps/%{app_name}/search'
- API_ACTION =
'/v3/openapi/apps/%{app_name}/%{table_name}/actions/bulk'
- ACTION_CMD_KEY =
'cmd'
- ACTION_CMD_INSERT =
'add'
- ACTION_CMD_UPDATE =
'update'
- ACTION_CMD_DELETE =
'delete'
Instance Method Summary collapse
-
#action(table_name, action, params) ⇒ Boolean
操作接口.
-
#delete(table_name, params) ⇒ Boolean
删除操作.
-
#insert(table_name, params) ⇒ Boolean
插入操作.
-
#search(params) ⇒ Hash
搜索接口.
-
#update(table_name, params) ⇒ Boolean
更新操作.
Instance Method Details
#action(table_name, action, params) ⇒ Boolean
Note:
操作接口的几个注意点(此为Aliyun Opensearch服务内部的处理)
-
add操作时, 如果数据已经存在, 会直接更新这条数据, 也不会报错
-
update操作时, 如果数据不存在, 不会直接新建数据, 也不会报错
-
delete操作时, 如果数据不存在, 不会进行操作, 也不会报错
操作接口
97 98 99 100 101 |
# File 'lib/aliyun/opensearch/client_ext/traffic/behavior.rb', line 97 def action(table_name, action, params) raise Error::EmptyParam if params.nil? || params.empty? self.call(:post, complete_path(API_ACTION, table_name: table_name), JSON.generate(complete_action_params(params, action)))['result'] end |
#delete(table_name, params) ⇒ Boolean
删除操作
78 79 80 |
# File 'lib/aliyun/opensearch/client_ext/traffic/behavior.rb', line 78 def delete(table_name, params) action(table_name, ACTION_CMD_DELETE, params) end |
#insert(table_name, params) ⇒ Boolean
插入操作
48 49 50 |
# File 'lib/aliyun/opensearch/client_ext/traffic/behavior.rb', line 48 def insert(table_name, params) action(table_name, ACTION_CMD_INSERT, params) end |
#search(params) ⇒ Hash
搜索接口
31 32 33 34 35 |
# File 'lib/aliyun/opensearch/client_ext/traffic/behavior.rb', line 31 def search(params) raise Error::EmptyParam if params.nil? || params.empty? self.call(:get, complete_path(API_SEARCH), params)['result'] end |
#update(table_name, params) ⇒ Boolean
更新操作
63 64 65 |
# File 'lib/aliyun/opensearch/client_ext/traffic/behavior.rb', line 63 def update(table_name, params) action(table_name, ACTION_CMD_UPDATE, params) end |