Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
cc10725c
Commit
cc10725c
authored
Jul 28, 2014
by
tvdavid
Committed by
Carsten Brandt
Sep 11, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for elasticsearch delete by query
close #4487
parent
259b8c90
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
6 deletions
+33
-6
Command.php
extensions/elasticsearch/Command.php
+28
-0
Query.php
extensions/elasticsearch/Query.php
+5
-6
No files found.
extensions/elasticsearch/Command.php
View file @
cc10725c
...
@@ -8,6 +8,8 @@
...
@@ -8,6 +8,8 @@
namespace
yii\elasticsearch
;
namespace
yii\elasticsearch
;
use
yii\base\Component
;
use
yii\base\Component
;
use
yii\base\InvalidCallException
;
use
yii\base\InvalidParamException
;
use
yii\helpers\Json
;
use
yii\helpers\Json
;
/**
/**
...
@@ -65,6 +67,32 @@ class Command extends Component
...
@@ -65,6 +67,32 @@ class Command extends Component
}
}
/**
/**
* Sends a request to the delete by query
* @param array $options
* @return mixed
*/
public
function
deleteByQuery
(
$options
=
[])
{
if
(
!
isset
(
$this
->
queryParts
[
'query'
]))
{
throw
new
InvalidCallException
(
'Can not call deleteByQuery when no query is given.'
);
}
$query
=
[
'query'
=>
$this
->
queryParts
[
'query'
],
];
if
(
isset
(
$this
->
queryParts
[
'filter'
]))
{
$query
[
'filter'
]
=
$this
->
queryParts
[
'filter'
];
}
$query
=
Json
::
encode
(
$query
);
$url
=
[
$this
->
index
!==
null
?
$this
->
index
:
'_all'
,
$this
->
type
!==
null
?
$this
->
type
:
'_all'
,
'_query'
];
return
$this
->
db
->
delete
(
$url
,
array_merge
(
$this
->
options
,
$options
),
$query
);
}
/**
* Sends a request to the _suggest API and returns the result
* Sends a request to the _suggest API and returns the result
* @param string|array $suggester the suggester body
* @param string|array $suggester the suggester body
* @param array $options
* @param array $options
...
...
extensions/elasticsearch/Query.php
View file @
cc10725c
...
@@ -267,17 +267,16 @@ class Query extends Component implements QueryInterface
...
@@ -267,17 +267,16 @@ class Query extends Component implements QueryInterface
/**
/**
* Executes the query and deletes all matching documents.
* Executes the query and deletes all matching documents.
*
*
*
This will not run facet queries
.
*
Everything except query and filter will be ignored
.
*
*
* @param Connection $db the database connection used to execute the query.
* @param Connection $db the database connection used to execute the query.
* If this parameter is not given, the `elasticsearch` application component will be used.
* If this parameter is not given, the `elasticsearch` application component will be used.
* @return array the query results. If the query results in nothing, an empty array will be returned.
* @param array $options The options given with this query.
* @return array the query results.
*/
*/
public
function
delete
(
$db
=
null
)
public
function
delete
(
$db
=
null
,
$options
=
[]
)
{
{
// TODO implement http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-delete-by-query.html
return
$this
->
createCommand
(
$db
)
->
deleteByQuery
(
$options
);
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/_search_requests.html
throw
new
NotSupportedException
(
'Delete by query is not implemented yet.'
);
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment