es Queries and filters
2016-03-10 16:05
1241 查看
Query DSL changesedit
On this page
Queries and filters mergedtermsquery and filter
orand
andnow implemented via
bool
filteredquery and
queryfilter deprecated
Filter auto-caching
Numeric queries use IDF for scoring
Fuzziness and fuzzy-like-this
More Like This
limitfilter deprecated
Java plugins registering custom queries
Elasticsearch Reference:
Getting Started
Setup
Breaking changes
Breaking changes in 2.2
Breaking changes in 2.1
Breaking changes in 2.0
Removed features
Network changes
Multiple
path.datastriping
Mapping changes
CRUD and routing changes
Query DSL changes
Search changes
Aggregation changes
Parent/Child changes
Scripting changes
Index API changes
Snapshot and Restore changes
Plugin and packaging changes
Setting changes
Stats, info, and
catchanges
Java API changes
Breaking changes in 1.6
Breaking changes in 1.4
Breaking changes in 1.0
API Conventions
Document APIs
Search APIs
Aggregations
Indices APIs
cat APIs
Cluster APIs
Query DSL
Mapping
Analysis
Modules
Index Modules
Testing
Glossary of terms
Release Notes
Queries and filters mergededit
Queries and filters have been merged — all filter clauses are now query clauses. Instead, query clauses can now be used in query context or in filter context:Query context
A query used in query context will calculate relevance scores and will not be cacheable. Query context is used whenever filter context does not apply.
Filter context
A query used in filter context will not calculate relevance scores, and will be cacheable. Filter context is introduced by:
the
constant_scorequery
the
must_notand (newly added)
filterparameter in the
boolquery
the
filterand
filtersparameters in the
function_scorequery
any API called
filter, such as the
post_filtersearch parameter, or in aggregations or index aliases
terms
query and filteredit
The executionoption of the
termsfilter is now deprecated and is ignored if provided. Similarly, the
termsquery no longer supports the
minimum_should_matchparameter.
or
and and
now implemented via bool
edit
The orand
andfilters previously had a different execution pattern to the
boolfilter. It used to be important to use
and/
orwith certain filter clauses, and
boolwith others.
This distinction has been removed: the
boolquery is now smart enough to handle both cases optimally. As a result of this change, the
orand
andfilters are now sugar syntax which are executed internally as a
boolquery. These filters may be removed in the future.
filtered
query and query
filter deprecatededit
The queryfilter is deprecated as is it no longer needed — all queries can be used in query or filter context.
The
filteredquery is deprecated in favour of the
boolquery. Instead of the following:
GET _search {"query":{"filtered":{"query":{"match":{"text":"quick brown fox"}},"filter":{"term":{"status":"published"}}}}}
move the query and filter to the
mustand
filterparameters in the
boolquery:
GET _search {"query":{"bool":{"must":{"match":{"text":"quick brown fox"}},"filter":{"term":{"status":"published"}}}}}
Filter auto-cachingedit
It used to be possible to control which filters were cached with the _cacheoption and to provide a custom
_cache_key. These options are deprecated and, if present, will be ignored.
Query clauses used in filter context are now auto-cached when it makes sense to do so. The algorithm takes into account the frequency of use, the cost of query execution, and the cost of building the filter.
The
termsfilter lookup mechanism no longer caches the values of the document containing the terms. It relies on the filesystem cache instead. If the lookup index is not too large, it is recommended to replicate it to all nodes by setting
index.auto_expand_replicas: 0-allin order to remove the network overhead as well.
Numeric queries use IDF for scoringedit
Previously, term queries on numeric fields were deliberately prevented from using the usual Lucene scoring logic and this behaviour was undocumented and, to some, unexpected.Single
termqueries on numeric fields now score in the same way as string fields, using IDF and norms (if enabled).
To query numeric fields without scoring, the query clause should be used in filter context, e.g. in the
filterparameter of the
boolquery, or wrapped in a
constant_scorequery:
GET _search {"query":{"bool":{"must":[{"match":{"numeric_tag":5}}],"filter":[{"match":{
"count":5}}]}}}
![]() | This clause would include IDF in the relevance score calculation. |
![]() | This clause would have no effect on the relevance score. |
Fuzziness and fuzzy-like-thisedit
Fuzzy matching used to calculate the score for each fuzzy alternative, meaning that rare misspellings would have a higher score than the more common correct spellings. Now, fuzzy matching blends the scores of all the fuzzy alternatives to use the IDF of the most frequently occurring alternative.Fuzziness can no longer be specified using a percentage, but should instead use the number of allowed edits:
0,
1,
2, or
AUTO(which chooses
0,
1, or
2based on the length of the term)
The
fuzzy_like_thisand
fuzzy_like_this_fieldqueries used a very expensive approach to fuzzy matching and have been removed.
More Like Thisedit
The More Like This (mlt) API and the
more_like_this_field(
mlt_field) query have been removed in favor of the
more_like_thisquery.
The parameter
percent_terms_to_matchhas been removed in favor of
minimum_should_match.
limit
filter deprecatededit
The limitfilter is deprecated and becomes a no-op. You can achieve similar behaviour using the terminate_after parameter.
Java plugins registering custom queriesedit
Java plugins that register custom queries can do so by using the IndicesQueriesModule#addQuery(Class<? extends QueryParser>)method. Other ways to register custom queries are not supported anymore.
https://www.elastic.co/guide/en/elasticsearch/reference/2.2/breaking_20_query_dsl_changes.html#_queries_and_filters_merged
相关文章推荐
- es Queries and filters demo
- local class incompatible: stream classdesc serialVersionUID
- Java GUI图形界面开发工具
- Form action defaulting to 'action' attribute's literal value .
- 远程调用服务(RPC)和消息(Message Queue)对比及其适用/不适用场合
- Druid连接池 一个设置 removeAbandonedTimeout
- Querydsl
- java序列化和serialVersionUID 总结
- Google guice
- common,Google Guava,Guice
- Lucene--FuzzyQuery与WildCardQuery(通配符)
- ConcurrentLinkedQueue
- ArrayBlockingQueue、LinkedBlockingQueue、ConcurrentLinkedQueue
- 字符集编码插入Mysql数据库是,字符utf8编码超过3位时的错误以及解决,Incorrect string value: '\xF0\xA1\xBF\xA8\
- LinkedBlockingQueue和ConcurrentLinkedQueue
- lucene4.7 正则查询(RegexpQuery)(八)
- Exception in thread &quot;AWT-EventQueue-0&quot; java.awt.HeadlessException:
- 数据库参考,键值(Key-value)数据库,列式存储,文档型数据库,图型数据库
- Storm UI
- 使用SoapUI 测试Web Service