https://www.elastic.co/guide/en/elasticsearch/client/java-api/6.1/java-term-level-queries.html
Find documents which contain the exact term specified in the field specified.
package cn.hadron;
import cn.hadron.es.QueryUtil;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
public class TermQuery {
public static void main(String[] args) {
QueryUtil util=new QueryUtil("website",5);
//构造查询对象
QueryBuilder qb=QueryBuilders.termQuery("title","vmware");
util.query(qb).print();
}
}
source:{ "title": "vmware复制虚拟机","author":"程裕强","postdate":"2016-12-29","abstract":"vmware复制虚拟机","url":"http://url.cn/53946664"}
index:website
type:blog
id:4
author=程裕强
postdate=2016-12-29
abstract=vmware复制虚拟机
title=vmware复制虚拟机
url=http://url.cn/53946664
Find documents which contain any of the exact terms specified in the field specified.
public static void main(String[] args) {
QueryUtil util=new QueryUtil("website",5);
//构造查询对象
QueryBuilder qb=QueryBuilders.termsQuery("title","centos","yum");
util.query(qb).print();
}
source:{ "title": "CentOS更换国内yum源","author":"程裕强","postdate":"2016-12-30","abstract":"CentOS更换国内yum源","url":"http://url.cn/53946911"}
index:website
type:blog
id:6
author=程裕强
postdate=2016-12-30
abstract=CentOS更换国内yum源
title=CentOS更换国内yum源
url=http://url.cn/53946911
source:{ "title": "CentOS升级gcc","author":"程裕强","postdate":"2016-12-25","abstract":"CentOS升级gcc","url":"http://url.cn/53868915"}
index:website
type:blog
id:3
author=程裕强
postdate=2016-12-25
abstract=CentOS升级gcc
title=CentOS升级gcc
url=http://url.cn/53868915
Find documents where the field specified contains values (dates, numbers, or strings) in the range specified.
public static void main(String[] args) {
QueryUtil util=new QueryUtil("website",5);
//构造查询对象
QueryBuilder qb=QueryBuilders.rangeQuery("postdate").from("2017-01-01").to("2017-12-31").format("yyyy-MM-dd");
util.query(qb).print();
}
source:{ "title": "es高亮","author":"程裕强","postdate":"2017-01-03","abstract":"Elasticsearch查询关键字高亮","url":"http://url/53991802"}
index:website
type:blog
id:8
author=程裕强
postdate=2017-01-03
abstract=Elasticsearch查询关键字高亮
title=es高亮
url=http://url/53991802
Find documents where the field specified contains any non-null value.
Find documents where the field specified contains terms which being with the exact prefix specified.
package cn.hadron;
import cn.hadron.es.QueryUtil;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
public class TermQuery {
public static void main(String[] args) {
QueryUtil util=new QueryUtil("my-index",5);
//构造查询对象
QueryBuilder qb=QueryBuilders.prefixQuery("name","程");
util.query(qb).print();
}
}
source:{
"name":"程裕强",
"age":31,
"gender":"男",
"salary":20000,
"dep":"bigdata"
}
index:my-index
type:persion
id:5
gender=男
name=程裕强
salary=20000
age=31
dep=bigdata
Find documents where the field specified contains terms which match the pattern specified, where the pattern supports single character wildcards (?) and multi-character wildcards (*)
public static void main(String[] args) {
QueryUtil util=new QueryUtil("website",5);
//构造查询对象
QueryBuilder qb=QueryBuilders.wildcardQuery("title","*yum*");
util.query(qb).print();
}
source:{ "title": "CentOS更换国内yum源","author":"程裕强","postdate":"2016-12-30","abstract":"CentOS更换国内yum源","url":"http://url.cn/53946911"}
index:website
type:blog
id:6
author=程裕强
postdate=2016-12-30
abstract=CentOS更换国内yum源
title=CentOS更换国内yum源
url=http://url.cn/53946911
Find documents where the field specified contains terms which match the regular expression specified.
public static void main(String[] args) {
QueryUtil util=new QueryUtil("website",5);
//构造查询对象
QueryBuilder qb=QueryBuilders.regexpQuery("title","gc.*");
util.query(qb).print();
}
source:{ "title": "CentOS升级gcc","author":"程裕强","postdate":"2016-12-25","abstract":"CentOS升级gcc","url":"http://url.cn/53868915"}
index:website
type:blog
id:3
author=程裕强
postdate=2016-12-25
abstract=CentOS升级gcc
title=CentOS升级gcc
url=http://url.cn/53868915
Find documents where the field specified contains terms which are fuzzily similar to the specified term. Fuzziness is measured as a Levenshtein edit distance of 1 or 2.
public static void main(String[] args) {
QueryUtil util=new QueryUtil("website",5);
//构造查询对象
QueryBuilder qb=QueryBuilders.fuzzyQuery("title","vmwere");
util.query(qb).print();
}
source:{ "title": "vmware复制虚拟机","author":"程裕强","postdate":"2016-12-29","abstract":"vmware复制虚拟机","url":"http://url.cn/53946664"}
index:website
type:blog
id:4
author=程裕强
postdate=2016-12-29
abstract=vmware复制虚拟机
title=vmware复制虚拟机
url=http://url.cn/53946664
Find documents of the specified type.
public static void main(String[] args) {
QueryUtil util=new QueryUtil("website",2);
//构造查询对象
QueryBuilder qb=QueryBuilders.typeQuery("blog");
util.query(qb).print();
}
source:{ "title": "libstdc++.so.6","author":"程裕强","postdate":"2016-12-30","abstract":"libstdc++.so.6问题解决","url":"http://url.cn/53946911"}
index:website
type:blog
id:5
author=程裕强
postdate=2016-12-30
abstract=libstdc++.so.6问题解决
title=libstdc++.so.6
url=http://url.cn/53946911
source:{ "title": "es高亮","author":"程裕强","postdate":"2017-01-03","abstract":"Elasticsearch查询关键字高亮","url":"http://url/53991802"}
index:website
type:blog
id:8
author=程裕强
postdate=2017-01-03
abstract=Elasticsearch查询关键字高亮
title=es高亮
url=http://url/53991802
Find documents with the specified type and IDs.
public static void main(String[] args) {
QueryUtil util=new QueryUtil("website",2);
//构造查询对象
QueryBuilder qb=QueryBuilders.idsQuery().addIds("1","3");
util.query(qb).print();
}
source:{ "title": "Ambari源码编译","author":"程裕强","postdate":"2016-12-21","abstract":"CentOS7.x下的Ambari2.4源码编译","url":"http://url.cn/53788351"}
index:website
type:blog
id:1
author=程裕强
postdate=2016-12-21
abstract=CentOS7.x下的Ambari2.4源码编译
title=Ambari源码编译
url=http://url.cn/53788351
source:{ "title": "CentOS升级gcc","author":"程裕强","postdate":"2016-12-25","abstract":"CentOS升级gcc","url":"http://url.cn/53868915"}
index:website
type:blog
id:3
author=程裕强
postdate=2016-12-25
abstract=CentOS升级gcc
title=CentOS升级gcc
url=http://url.cn/53868915