首页 > 技术文章 > 【ElasticSearch】查询使用学习

yangchongxing 2020-02-12 15:17 原文

【ElasticSearch】查询使用学习

=============================================================

1、条件统计件数

=============================================================

1、条件统计件数

{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "id": {
              "value": "100001"
            }
          }
        },
        {
          "term": {
            "name": {
              "value": "张三"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "id_count": {
      "value_count": {
        "field": "id"
      }
    }
  }
}

 

 

 

exists 查询和 missing 查询 SQL中的 IS_NULL (missing) 和 NOT IS_NULL (exists)

multi_match 多字段匹配

 

exists 查询和 missing 查询 SQL中的 IS_NULL (missing) 和 NOT IS_NULL (exists)

{
    "exists":   {
        "field":    "title"
    }
}

 

 

 

multi_match 多字段匹配

multi_match 查询可以在多个字段上执行相同的 match 查询

{
    "query": {
        "bool": {
            "must": [
                {
                    "multi_match": {
                        "fields": [
                            "id",
                            "position"
                        ],
                        "query": "100000"
                    }
                }
            ],
            "must_not": [
                
            ],
            "should": [
                
            ]
        }
    },
    "from": 0,
    "size": 10,
    "sort": [
        
    ],
    "aggs": {
        
    }
}

 

推荐阅读