Bodybuilder

An elasticsearch query body builder. Easily build complex queries for elasticsearch with a simple, predictable api.

Documentation Read the Docs github View on GitHub
x
 
1
bodybuilder()
2
        .query('match', 'message', 'this is a test')
3
        .filter('term', 'user', 'kimchy')
4
        .filter('term', 'user', 'herald')
5
        .orFilter('term', 'user', 'johnny')
6
        .notFilter('term', 'user', 'cassie')
7
        .aggregation('terms', 'user')
8
        .build()
1
48
 
1
{
2
  "query": {
3
    "bool": {
4
      "filter": {
5
        "bool": {
6
          "must": [
7
            {
8
              "term": {
9
                "user": "kimchy"
10
              }
11
            },
12
            {
13
              "term": {
14
                "user": "herald"
15
              }
16
            }
17
          ],
18
          "should": [
19
            {
20
              "term": {
21
                "user": "johnny"
22
              }
23
            }
24
          ],
25
          "must_not": [
26
            {
27
              "term": {
28
                "user": "cassie"
29
              }
30
            }
31
          ]
32
        }
33
      },
34
      "must": {
35
        "match": {
36
          "message": "this is a test"
37
        }
38
      }
39
    }
40
  },
41
  "aggs": {
42
    "agg_terms_user": {
43
      "terms": {
44
        "field": "user"
45
      }
46
    }
47
  }
48
}