查询
基于Term查询
- Term是表达语意的最小单位;
- 对输入不做分词处理,将输入作为一个整体,再倒排索引中查找准确的词项,并且为每个文档进行相关度算分
- 可以通过Constant Score将查询转换为Filtering,避免算分,并利用缓存,提高性能
GET accounts/_search{
"query": { "constant_score": { "filter": { "term": { "city": { "value": "brogan" } } } } }}
- 查询包括:
- Term Query
GET accounts/_search{
"explain": true,
"profile": "true",
"query": {
"term": { "city": { "value": "brogan" } } }}
- Range Query
GET accounts/_search{
"profile": "true",
"query": {
"range": { "age": { "gte": 10, "lte": 20 } } }}
- Exists Query
GET accounts/_search{
"query": { "exists": { "field": "age" } }}
- Prefix Query
GET accounts/_search{
"query": { "prefix": { "city": { "value": "a" } } }}
- Wildcard Query - 通配符查询(*匹配多个字符,?匹配单个字符)
GET accounts/_search{
"query": { "wildcard": { "email": { "value": "*duoflex.com" } } }}
基于全文本的查询
- 索引和搜索都会进行分词,查询字符串会先传递到一个分词器,然后生成一个供查询的词项列表
- 查询时,会现对输入进行分词,然后每个词项逐个进行查询,最终将结果合并。并为每一个文档算分
- 查询包含
- Match Query
GET accounts/_search{ "query": { "match_all": {} }}
- Match Phrase Query
GET accounts/_search{ "profile": "true", "query": { "match_phrase": { "address": "880 Holmes" } }
- Query String Query
GET accounts/_search{ "query": { "query_string": { "default_field": "address", "query": "880 Holmes" } }}
- explain:查看算分过程
- profile:查看查询过程查询类型