Skip to content

Commit

Permalink
delete index doc type
Browse files Browse the repository at this point in the history
  • Loading branch information
jea committed Dec 9, 2021
1 parent 301c1e8 commit e5215e7
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,15 @@ public function terminate(int $terminateAfter)
}

/**
* 设置当前es的查询index和type
* 设置当前es的查询index
*
* @param string $index index name
* @param string $type type name
*
* @return $this
*/
public function from($index, $type = "_docs")
public function from($index)
{
$this->conditions['index'] = $index;
$this->conditions['type'] = $type;

return $this;
}
Expand Down Expand Up @@ -416,7 +414,6 @@ public function debug()
* 更新字段 部分更新, 如果不存在将会返回错误
*
* @param string $index 索引名
* @param string $type type名
* @param mixed $id 被更新的文档id
* @param array $data 要更新的信息
* @param string $routing routing
Expand All @@ -425,20 +422,19 @@ public function debug()
* @throws \Exception
* @throws ESORMException
*/
public function update($index, $type, $id, $data, $routing = '', $docAsUpsert = false)
public function update($index, $id, $data, $routing = '', $docAsUpsert = true)
{
if (empty($index) || empty($type) || empty($id) || empty($data)) {
if (empty($index) || empty($id) || empty($data)) {
throw new ESORMException('in update , you must set index type id data');
}
$this->buildDsl();
$params = array(
'index' => $index,
'type' => $type,
'id' => $id,
'body' => array('doc' => $data),
);
if ($docAsUpsert) {
$params['body']['doc_as_upsert'] = true;
if (!$docAsUpsert) {
$params['body']['doc_as_upsert'] = false;
}

if ($routing !== '') {
Expand All @@ -452,7 +448,6 @@ public function update($index, $type, $id, $data, $routing = '', $docAsUpsert =
* 更新字段 部分更新, 如果不存在将会返回错误
*
* @param string $index 索引名
* @param string $type type名
* @param mixed $id 文档id
* @param array $data 要新增的信息
* @param string $routing routing
Expand All @@ -462,15 +457,14 @@ public function update($index, $type, $id, $data, $routing = '', $docAsUpsert =
*
* @throws ESORMException
*/
public function insert($index, $type, $id, $data, $routing = '')
public function insert($index, $id, $data, $routing = '')
{
if (empty($index) || empty($type) || empty($id) || empty($data)) {
throw new ESORMException('in create , you must set index type id data');
if (empty($index) || empty($id) || empty($data)) {
throw new ESORMException('in create , you must set index id data');
}
$this->buildDsl();
$params = array(
'index' => $index,
'type' => $type,
'id' => $id,
'body' => $data,
);
Expand All @@ -485,23 +479,21 @@ public function insert($index, $type, $id, $data, $routing = '')
* 删除一条数据, es的删除数据即使数据不存在 返回依然是执行成功的
*
* @param string $index index name
* @param string $type type name
* @param mixed $id id you want delete
*
* @return Format
* @throws \Exception
*
* @throws ESORMException
*/
public function delete($index, $type, $id)
public function delete($index, $id)
{
if (empty($index) || empty($type) || empty($id)) {
throw new ESORMException('in delete , you must set index type id');
if (empty($index) || empty($id)) {
throw new ESORMException('in delete , you must set index id');
}
$this->buildDsl();
$params = array(
'index' => $index,
'type' => $type,
'id' => $id,
);

Expand Down

0 comments on commit e5215e7

Please sign in to comment.