随着文档型数据库用得越来越多,ES使用也成了程序猿的常备技能,下面整理了工作中用到的ES搜索语法
{
"query" : {
"match_phrase" : {
"字段" : "搜索值"
}
}
}
{
"query": {
"match_phrase": {
"product_name" : {
"query" : "PHILIPS HX6730",
"slop" : 1
}
}
}
}
{
"query": {
"match_phrase_prefix": {
"product_name": "PHILIPS HX",
"slop": 5,
"max_expansions": 20
}
}
}
{
"query": {
"match": {"title": "串"}
},
"from": 10,
"size": 10
}
{
"query": {
"multi_match": {
"query": "串串",
"fields": [ "title", "tag"]
}
}
}
{
"query":{
"multi_match":{
"query":"aa",
"type" : "phrase_prefix",
"fields":["content_text"]
}
}
}
50%命中其中两个词就返回
{
"query": {
"match": {
"product_name": {
"query": "java 程序员 书 推荐",
"minimum_should_match": "50%"
}
}
}
}
{"query": {
"bool": {
"must": [
{"terms":{"node_standard_code":[1001,1002,1004,1007]}}
]
}
}
}
{
"query": {
"bool": {
"must": {
"match": {
"product_name": "toothbrush"
}
},
"filter": {
"range": {
"price": {
"gt": 400,
"lt": 700
}
}
}
}
}
}
{
"query": {
"constant_score": {
"filter": {
"terms": {
"product_name": [
"toothbrush",
"shell"
]
}
}
}
}
}
{
"query" : {
"constant_score" : {
"filter": {
"missing" : { "field" : "tags" }
}
}
}
}
{
"query" : {
"constant_score" : {
"filter" : {
"exists" : { "field" : "tags" }
}
}
}
}
{
"query": {
"prefix": {
"postcode": "W1"
}
}
}
{
"query": {
"wildcard": {
"affair_list.affairs_name.keyword": {
"value": "*%*"
}
}
}
}
{
"query": {
"wildcard": {
"affair_list.affairs_name.keyword": {
"value": "*\\**"
}
}
}
}
{
"query": {
"bool": {
"filter": {
"script": {
"script": "'10010001'.startsWith(doc['code.keyword'].value)"
}
}
}
}
}
{
"query": {
"bool": {
"fileter":[
{"range":{"date.keyword":{"gt":"20170101","lt":"20170201"}}}
],
"must":[
{
"bool":{
"should": [
{"term": {"A.keyword": "0000000000"}},
{"term": {"B.keyword": "0000000001"}}
]
}
}
]
}
}
}
{
"query": {
"bool": {
"should": [
{
"match": {
"product_name": "java"
}
},
{
"match": {
"product_name": "程序员"
}
},
{
"match": {
"product_name": "书"
}
},
{
"match": {
"product_name": "推荐"
}
}
],
"minimum_should_match": 3
}
}
}
{
"query":{
"script": {
"script": {
"inline": "doc['rr_mark_id'].value - doc['mr_mark_id'].value == 0",
"lang": "painless"
}
}
}
}
{"query": {
"bool": {
"filter": {
"term": {"status": "1"}
}
}
}
}