The default match query type is boolean type.
    curl -XPOST http://ip:9200/indexname/typename/_search 
    {
        "query":{
            "match" : {
                "message" : "this is a test"
            }
        }
    }
  • operator, this flag can be set to or or and, default is or.
下面两个query是等价的

    {
        "query":{
            "match" : {
                "title": "brown fox"
            }
        }
    }

    {
        "query":{
            "bool": {
                "should": [
                    { "term": { "title": "brown" }},
                    { "term": { "title": "fox"   }}
                ]
            }
        }
    }
下面两个query是等价的

    {
        "query":{
            "match" : {
                "title": "brown fox",
                "operator":"and"
            }
        }
    }

    {
        "query":{
            "bool": {
                "must": [
                    { "term": { "title": "brown" }},
                    { "term": { "title": "fox"   }}
                ]
            }
        }
    }
  • phrase 短语查询
下面两个query是等价的

    {
        "query":{
            "match_phrase" : {
                "message" : "this is a test"
            }
        }
    }

    {
        "query":{
            "match" : {
                "message" : {
                    "query" : "this is a test",
                    "type" : "phrase"
                }
            }
        }
    }
  • match_phrase_prefix
下面两个query是等价的

    {
        "query":{
            "match_phrase_prefix" : {
                "message" : "this is a test"
            }
        }
    }

    {
        "query":{
            "match" : {
                "message" : {
                    "query" : "this is a test",
                    "type" : "phrase_prefix"
                }
            }
        }
    }
  • minimum_should_match 指定最少匹配多少
    {
        "query":{
            "match" : {
                "title": "quick brown fox",
                "minimum_should_match":"75%"
            }
        }
    }

    {
        "query":{
            "bool": {
                "should": [
                    { "term": { "title": "quick" }},
                    { "term": { "title": "brown" }},
                    { "term": { "title": "fox"   }}
                ],
                "minimum_should_match":2
            }
        }
    }
    因为只有3个查询语句,minimum_should_match的值75%会被向下舍入到2。即至少两个should语句需要匹配。
  • zero_terms_query, can be set to none or all, default is none. The all is corresponds to a match all query.

  • or

      {
          "query":{
              "match":{
                  "promotionProductUid":"43397603323925032|43397603324931086"
              }
          }
      }
    
⤧  Next post elasticsearch query(基本查询) ⤧  Previous post elasticsearch type(type)