Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
Elasticsearch DSL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Public
Elasticsearch DSL
Commits
136ff817
Commit
136ff817
authored
9 years ago
by
Aivaras Gotovskis
Browse files
Options
Downloads
Patches
Plain Diff
Add bool filter doc.
parent
ac05db95
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/Filter/Bool.md
+96
-0
96 additions, 0 deletions
docs/Filter/Bool.md
with
96 additions
and
0 deletions
docs/Filter/Bool.md
0 → 100644
+
96
−
0
View file @
136ff817
# Bool Filter
> More info about filter query is in the [official elasticsearch docs][1]
A filter that matches documents matching boolean combinations of other queries. Similar in concept to
[
Boolean query
][
2
]
, except that the clauses are other filters.
To create a bool filter unlike other queries you don't have to create
`BoolFilter`
object. Just add queries to the
search object and it will form bool filter automatically.
Lets take an example to write a bool query with Elasticsearch DSL.
```
JSON
{
"filtered" : {
"query" : {
"queryString" : {
"default_field" : "message",
"query" : "elasticsearch"
}
},
"filter" : {
"bool" : {
"must" : {
"term" : { "tag" : "wow" }
},
"must_not" : {
"range" : {
"age" : { "gte" : 10, "lt" : 20 }
}
},
"should" : [
{
"term" : { "tag" : "sometag" }
},
{
"term" : { "tag" : "sometagtag" }
}
]
}
}
}
}
```
And now the query via DSL:
```
php
$queryStringQuery
=
new
QueryStringQuery
(
'elasticsearch'
,
[
'default_field'
=>
'message'
]);
$termFilter1
=
new
TermFilter
(
'tag'
,
'wow'
);
$rangeFilter
=
new
RangeFilter
(
'age'
,
[
'gte'
=>
10
,
'lt'
=>
20
]);
$termFilter2
=
new
TermFilter
(
'tag'
,
'sometag'
);
$termFilter3
=
new
TermFilter
(
'tag'
,
'sometagtag'
);
$search
=
new
Search
();
$search
->
addQuery
(
$queryStringQuery
);
$search
->
addFilter
(
$termFilter1
);
$search
->
addFilter
(
$rangeFilter
,
BoolFilter
::
MUST_NOT
);
$search
->
addFilter
(
$termFilter2
,
BoolFilter
::
SHOULD
);
$search
->
addFilter
(
$termFilter3
,
BoolFilter
::
SHOULD
);
$queryArray
=
$search
->
toArray
();
```
There is also an exception due adding filters to the search. If you add only one filter without type
it will form simple query. e.g. lets try to create match all filter.
```
php
$matchAllFilter
=
new
MatchAllFilter
();
$search
=
new
Search
();
$search
->
addFilter
(
$matchAllFilter
);
$queryArray
=
$search
->
toArray
();
```
You will get this query:
```
JSON
{
"query": {
"filtered": {
"filter": {
"match_all": {}
}
}
}
}
```
> More info about `Search` look in the [How to search](../HowTo/HowToSearch.md) chapter.
[
1
]:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-filter.html
[
2
]:
../Query/Bool.md
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment