ElasticSearch是基于lucene的开源搜索引擎,它的查询语法关键字跟lucene一样,如下:

  • 分页:from/size
  • 字段:fields
  • 排序:sort
  • 查询:query
  • 过滤:filter
  • 高亮:highlight
  • 统计:facet

参考资料:

http://blog.csdn.net/lgnlgn/article/details/8053626

 

查询:query

对于每个查询项,我们可以通过must、should、mustNot方法对QueryBuilder进行组合,形成多条件查询。(must=>and,should=>or)

 

Lucene支持基于词条的TermQuery、RangeQuery、PrefixQuery、BolleanQuery、PhraseQuery、WildcardQuery、FuzzyQuery

1.TermQuery与QueryParser
单个单词作为查询表达式时,它相当于一个单独的项。如果表达式是由单个单词构成,QueryParser的parse()方法会返回一个TermQuery对象。
如查询表达式为:content:hello,QueryParser会返回一个域为content,值为hello的TermQuery。
Query query = new TermQuery(“content”, “hello”).

2.RangeQuery与QueryParser
QueryParse可以使用[起始TO 终止]或{起始TO 终止}表达式来构造RangeQuery。
如查询表达式为:time:[20101010 TO 20101210] ,QueryParser会返回一个域为time,下限为20101010,上限为20101210的RangeQuery。
Term t1 = new Term(“time”, “20101010”);
Term t2 = new Term(“time”, “20101210”);
Query query = new RangeQuery(t1, t2, true);

3.PrefixQuery与QueryParser
当查询表达式中短语以星号(*)结尾时,QueryParser会创建一个PrefixQuery对象。
如查询表达式为:content:luc*,则QueryParser会返回一个域为content,值为luc的PrefixQuery.
Query query = new PrefixQuery(luc);

4.BooleanQuery与QueryParser
当查询表达式中包含多个项时,QueryParser可以方便的构建BooleanQuery。QueryParser使用圆括号分组,通过-,+,AND, OR及NOT来指定所生成的Boolean Query。

5.PhraseQuery与QueryParser
在QueryParser的分析表达式中双引号的若干项会被转换为一个PhraseQuery对象,默认情况下,Slop因子为0,可以在表达式中通过~n来指定slop因子的值。
如查询表达式为content:“hello world”~3,则QueryParser会返回一个域为content,内容为“hello world”,slop为3的短语查询。
Query query = new PhraseQuery();
query.setSlop(3);
query.add(new Term(“content”, “hello”);
query.add(new Term(“content”, “world”);

6. Wildcard与QueryParser
    Lucene使用两个标准的通配符号,*代表0或多个字母,?代表0或1个字母。但查询表达式中包含*或?时,则QueryParser会返回一个WildcardQuery对象。但要注意的是,当*出现在查询表达式的末尾时,会被优化为PrefixQuery;并且查询表达式的首个字符不能是通配符,防止用户输入以通配符*为前缀的搜索表达式,导致lucene枚举所有的项而耗费巨大的资源。

6.FuzzyQuery和QueryParser
QueryParser通过在某个项之后添加“~”来支持FuzzyQuery类的模糊查询。

 

 

参考:

http://wenku.baidu.com/view/3c90138283d049649b66588c.html 

http://wenku.baidu.com/view/3f8161d949649b6648d7470b.html

ElasticSearch 查询语法的更多相关文章

  1. elasticsearch基本概念与查询语法

    序言 后面有大量类似于mysql的sum, group by查询 elk === elk总体架构 https://www.elastic.co/cn/products Beat 基于go语言写的轻量型 ...

  2. Func<T,T>应用之Elasticsearch查询语句构造器的开发

    前言 之前项目中做Elasticsearch相关开发的时候,虽然借助了第三方的组件PlainElastic.Net,但是由于当时不熟悉用法,而选择了自己拼接查询语句.例如: string queryG ...

  3. Elasticsearch Kibana查询语法

    Elasticsearch Kibana查询语法 2018年06月03日 23:52:30 wangpei1949 阅读数:3992   Elasticsearch Kibana Discover的搜 ...

  4. ES 07 - Elasticsearch查询文档的六种方法

    目录 1 Query String Search(查询串检索) 2 Query DSL(ES特定语法检索) 3 Query Filter(过滤检索) 4 Full Text Search(全文检索) ...

  5. elasticsearch查询语句

    1,安装es 安装java环境 # java --versionjava version "1.8.0_65" Java(TM) SE Runtime Environment (b ...

  6. elasticsearch查询语句总结

    query 和  filter 的区别请看:https://www.cnblogs.com/bainianminguo/articles/10396956.html Filter DSL term 过 ...

  7. query_string查询支持全部的Apache Lucene查询语法 低频词划分依据 模糊查询 Disjunction Max

    3.3 基本查询3.3.1词条查询 词条查询是未经分析的,要跟索引文档中的词条完全匹配注意:在输入数据中,title字段含有Crime and Punishment,但我们使用小写开头的crime来搜 ...

  8. python连接 elasticsearch 查询数据,支持分页

    使用python连接es并执行最基本的查询 from elasticsearch import Elasticsearch es = Elasticsearch(["localhost:92 ...

  9. Filter DSL 常用语法 -- 基本查询语法,必会

    转发自:https://www.cnblogs.com/ghj1976/p/5293250.html term 过滤 term主要用于精确匹配哪些值,比如数字,日期,布尔值或 not_analyzed ...

随机推荐

  1. React组件生命周期-正确执行运行阶段的函数

    一. 二. <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset=" ...

  2. Win软件私家珍藏-常用软件工具使用总结

    原文:Win软件私家珍藏-常用软件工具使用总结 Windowns常用软件 看图 FastStoneImageViewer 免费软件,好用到爆!没广告!功能齐全!不光能看图,还能修图! Picasa3 ...

  3. 利用SOLR搭建企业搜索平台 之——运行solr

    来源:http://blog.csdn.net/zx13525079024/article/details/24806131 本节主要介绍Solr的安装,其实Solr不需要安装.直接下载就可以了    ...

  4. 重新安装sqlyog时备份数据库链接列表的方法

    一般在本机C:\Documents and Settings\Administrator\Application Data\SQLyog这个目录下有个sqlyog.ini文件.把这个文件备份一下就ok ...

  5. AIX 内存使用情况

    cat > WHAT_EVER_YOU_WANT.sh#!/usr/bin/ksh#memory calculatorum=`svmon -G | head -2|tail -1| awk {' ...

  6. leetcode:Number of 1 Bits

    Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...

  7. leetcode:Contains Duplicate和Contains Duplicate II

    一.Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your fun ...

  8. HibernateTools实现pojo类 数据库schma mapping映射的相互转换

    核心 利用HibernateTools,从POJO类,Mapping映射文件,数据库表有其中的一项,就能生成其他两项. 概述 在使用Hibernate开发系统持久层时,按照一般开发流程 1.分析业务 ...

  9. Eclipse常用的插件安装

    嫌公司用的eclipse不爽,准备自己弄一个,diy的,没想到装插得烦死人. 诱惑人的“常用插件”: (1)    AmaterasUML        介绍:Eclipse的UML插件,支持UML活 ...

  10. JS 去除字符串中的空格

    1. 去掉字符串前后所有空格: 代码如下: function Trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); } 说明: ...