作者: 石文
时间:2019-04-02
基本查询
Term查询
{
"query": {
"term": {
"title": "crime"
}
}
}
#范例2,指定得分权重,boost
{
"query": {
"term": {
"title": {
"value":"crime",
"boost":10.0
}
}
}
}
#范例3:多term查询
{
"query": {
"terms": {
"tags": ["novel","book"]
}
}
}
常用词查询:高低频查询
{
"query": {
"common": {
"title":{
"query":"crime and punishment",
"cutoff_frequency":0.001
}
}
}
}
match查询
{
"query": {
"match": {
"title": "crime and punishment"
}
}
}
#范例2
{
"query": {
"match": {
"title": {
"query":"crime and punishment",
"operator":"and" #要求and或者or匹配文本的分词
}
}
}
}
query_string查询
标识符查询
前缀查询
{
"query": {
"prefix": {
"title":"cri"
}
}
}
#指定权重
{
"query": {
"prefix": {
"title":{
"value":"cri",
"boost":3.0
}
}
}
}
fuzzy查询
通配符查询
{
"query": {
"wildcard": {
"title": "cr?me"
}
}
}
范围查询
{
"query": {
"range": { #只能针对单个字段,可以是数值型的,也可以是基于字符串的。
"year": {
"gte" :1890,
"lte":1900
}
}
}
}
正则表达式查询
{
"query": {
"regexp": {
"title": {
"value" :"cr.m[ae]",
"boost":10.0
}
}
}
}
布尔组合查询
{
"query": {
"bool": {
"must": {
"term": {
"title": "crime"
}
},
"should": {
"range": {
"year": {
"from": 1900,
"to": 2000
}
}
},
"must_not": {
"term": {
"otitle": "nothing"
}
}
}
}
}