ElasticSearch 진행 and, or, in, not in 다중 조건 조합 DSL 구조화 조회

23076 단어 ElasticSearch

1, 두 가지 조건 및 질문:

SELECT * FROM t_test_info t WHERE t.kv.p.keyword = '123' AND t.kv.b.keyword = 'p'
 size
GET /t_test_info/_search
{
  "size": 0, 
  "from": 0,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "kv.p.keyword": "123"
          }
        },
        {
          "term": {
            "kv.b.keyword": "p"
          }
        }
      ],
      "must_not": [],
      "should": []
    }
  },
  "sort": [],
  "aggs": {}
}
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 4,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

2. 같은 필드 in 질문:

SELECT * FROM t_test_info t WHERE t.client_ip in ('123' , '1234')
GET /t_test_info/_search
{
  "size": 0, 
  "from": 0,
  "query": {
    "terms": {
      "client_ip": [
        "123","1234"
      ]
    }
  },
  "sort": [],
  "aggs": {}
}
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 9,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

3, 두 필드 or 질문:

SELECT * FROM t_test_info t WHERE t.client_ip = '123' or t.kv.b = 'l'
GET /t_test_info/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "term": {
            "client_ip": "123"
          }
        },
        {
          "term": {
            "kv.b": "l"
          }
        }
      ],
      "must_not": [],
      "must": []
      
    }
  },
  "from": 0,
  "size": 0,
  "sort": [],
  "aggs": {}
}
{
  "took" : 699,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 24,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

4, 필드 not in 문제:

SELECT * FROM t_test_info t WHERE t.client_ip not in ('123', '1234')
GET /t_test_info/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "term": {
            "client_ip": "123"
          }
        }
      ],
      "must": [],
      "should": []
    }
  },
  "from": 0,
  "size": 0,
  "sort": [],
  "aggs": {}
}

5, 두 필드 not in 문제:

SELECT * FROM t_test_info t WHERE t.client_ip not in ('123') and t.@timestamp not in ("2020-05-15T15:13:47.000Z");
GET /t_test_info/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "term": {
            "client_ip": "123"
          }
        },
        {
          "term": {
            "@timestamp": "2020-05-15T15:13:47.000Z"
          }
        }
      ],
      "should": []     
    }
  },
  "from": 0,
  "size": 0,
  "sort": [],
  "aggs": {}
}

결과:
{
  "took" : 7,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 343,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

ElasticSearch의 간단한 API 작업으로 다른 문서를 볼 수 있습니다.
ElasticSearch RESTFUL API의 간단한 작업

좋은 웹페이지 즐겨찾기