Elasticsearch的DSL之 term and match
来源:互联网 发布:民治数据 编辑:程序博客网 时间:2024/05/12 23:27
记录学习ES的DSL的一些比较重要的概念和方法。
term VS match
首先要说的是, 一个doc进入ES被索引,哪些字段(fields)被索引是可以自定义的。 默认,ES会对所有的fields进行索引。
PUT /my_index{ "mappings": { "my_type": { "properties": { "status_code": { "type": "string", "index": "not_analyzed" } } } }}
这是个简单的mapping, 有个status_code字段,类型是string, index的方式是“not_analyzed”。 ES中某个字段的index方式有三种值:no/not_analyzed/analyzed, 对应的意思是:
no = > 该字段不进入index, 即不可对该字段进行query。
not_analyzed => 该字段作为一个term进入index,不进行分词等analyse操作。对除string类型之外的fields, 这个是默认的。对string类型的字段,默认要进行分词的,除非指定不进行分词(即not_analyzed) 。
analyzed =》 只对string类型的field有效, 且是默认的。 通过analyzer, 该field会被切分成若干的分词(terms),
再来说,term和match
term是用来进行分词精确匹配的(The term query finds documents that contain the exact term specified in the inverted index.)
match是用来进行全文检索的(full-text search)。
看下面的一个例子, 就能够很清楚的知道二者的区别了。例子来自https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
myindex下的一个类型是my_type的mapping:
PUT my_index{ "mappings": { "my_type": { "properties": { "full_text": { "type": "string" }, "exact_value": { "type": "string", "index": "not_analyzed" } } } }}PUT my_index/my_type/1{ "full_text": "Quick Foxes!", "exact_value": "Quick Foxes!" }
The full_text field is analyzed by default.
The exact_value field is set to be not_analyzed.
The full_text inverted index will contain the terms: [quick, foxes].
The exact_value inverted index will contain the exact term: [Quick Foxes!].
Now, compare the results for the term query and the match query:
(1)GET my_index/my_type/_search{ "query": { "term": { "exact_value": "Quick Foxes!" } }}(2)GET my_index/my_type/_search{ "query": { "term": { "full_text": "Quick Foxes!" } }}(3)GET my_index/my_type/_search{ "query": { "term": { "full_text": "foxes" } }}(4)GET my_index/my_type/_search{ "query": { "match": { "full_text": "Quick Foxes!" } }}
This query matches because the exact_value
field contains the exact term Quick Foxes!
.
This query does not match, because the full_text
field only contains the terms quick
andfoxes
. It does not contain the exact term Quick Foxes!
.
A term
query for the term foxes
matches the full_text
field.
This match
query on the full_text
field first analyzes the query string, then looks for documents containing quick
or foxes
or both.
- Elasticsearch的DSL之 term and match
- Elasticsearch的DSL之query and filter
- Elasticsearch学习系列之term和match查询
- elasticsearch 查询match和term
- ElasticSearch之term vector
- elasticsearch 查询(match和term)
- elasticsearch 查询(match和term)
- elasticsearch 查询(match和term)
- elasticsearch 查询(match和term)
- elasticsearch 查询(match和term)
- elasticsearch 查询(match和term)
- elasticsearch 查询(match和term)
- elasticsearch 查询(match和term)
- elasticsearch 查询(match和term)
- elasticsearch 查询(match和term)【转载】
- Elasticsearch查询match、term和bool区别
- elasticsearch 查询(match和term)
- elasticsearch 查询(match和term)
- Android和H5的交互问题
- 链表与树
- Qt QLabel左跑马显示文字
- android loader用法
- 二叉树构建,先序,中序,后序遍历(以及非递归实现),广度优先遍历
- Elasticsearch的DSL之 term and match
- php socket function
- Protocol Buffer
- c++作业4
- c#高级编程
- Servlet 作业
- SlidingMenue布局问题
- C++实验4——输出星号图
- 走近人脸检测:从VJ到深度学习(下)