Module: Aliyun::Opensearch::ClientExt::Traffic::Behavior

Included in:
Aliyun::Opensearch::Client
Defined in:
lib/aliyun/opensearch/client_ext/traffic/behavior.rb

Overview

各种接口行为

Author:

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

Instance Method Details

#action(table_name, action, params) ⇒ Boolean

Note:

操作接口的几个注意点(此为Aliyun Opensearch服务内部的处理)

  1. add操作时, 如果数据已经存在, 会直接更新这条数据, 也不会报错

  2. update操作时, 如果数据不存在, 不会直接新建数据, 也不会报错

  3. delete操作时, 如果数据不存在, 不会进行操作, 也不会报错

操作接口

Parameters:

  • table_name (String)

    操作对象的表名

  • action (String)

    操作类型

  • params (Array|Hash)

    参数

Returns:

  • (Boolean)

    处理结果

Raises:

Author:



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

删除操作

Parameters:

  • table_name (String)

    操作对象的表名

  • params (Hash)

    参数

Returns:

  • (Boolean)

    处理结果

See Also:

Author:



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

插入操作

Parameters:

  • table_name (String)

    操作对象的表名

  • params (Hash)

    参数

Returns:

  • (Boolean)

    处理结果

See Also:

Author:



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

搜索接口

Parameters:

  • params (Hash)

    参数

Returns:

  • (Hash)

    查询结果

Raises:

See Also:

Author:



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

更新操作

Parameters:

  • table_name (String)

    操作对象的表名

  • params (Hash)

    参数

Returns:

  • (Boolean)

    处理结果

See Also:

Author:



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