title: Elastic Spring Data OR Java High Level REST Client?
body: <p>I'm new to both Elasticsearch and Spring. I've written a Javascript POC that converts a JSON string into an Elasticsearch query (and performs the request). 
  It takes a string like this:</p>
  
  <pre><code>{
      "period": "years",
      "format": "xml",
      "criteria": {
          "operator": "OR",
          "operands": [
              {
                  "operator": "AND",
                  "operands": [
                      {
                          "operator": "exists",
                          "field": "def"
                      },
                      {
                          "operator": "includes",
                          "field": "keywords",
                          "value": [
                              "abcd"
                          ]
                      }
                  ]
              },
              {
                  "operator": "AND",
                  "operands": [
                      {
                          "operator": "from",
                          "field": "links",
                          "value": 1
                      },
                      {
                          "operator": "includes",
                          "field": "keywords",
                          "value": [
                              "abcd",
                              "efgh"
                          ]
                      }
                  ]
              }
          ]
      }
  }
  </code></pre>
  
  <p>(Note: This query may have any levels of nesting)</p>
  
  <p>... and converts it into this:</p>
  
  <pre><code>{
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "should": [
                {
                  "bool": {
                    "must": [
                      {
                        "bool": {
                          "must": [
                            {
                              "exists": {
                                "field": "def"
                              }
                            },
                            {
                              "range": {
                                "effectiveDate": {
                                  "gte": 1543982400,
                                  "lt": 1575518400
                                }
                              }
                            }
                          ]
                        }
                      },
                      {
                        "bool": {
                          "must": [
                            {
                              "terms": {
                                "keywords.name": [
                                  "abcd",
                                  "efgh"
                                ]
                              }
                            },
                            {
                              "range": {
                                "effectiveDate": {
                                  "gte": 1543982400,
                                  "lt": 1575518400
                                }
                              }
                            }
                          ]
                        }
                      }
                    ]
                  }
                },
                {
                  "bool": {
                    "must": [
                      {
                        "bool": {
                          "must": {
                            "terms": {
                              "links": [
                                11048,
                                34618,
                                34658
                              ]
                            }
                          }
                        }
                      },
                      {
                        "bool": {
                          "must": [
                            {
                              "terms": {
                                "keywords.name": [
                                  "abcd",
                                  "efgh"
                                ]
                              }
                            },
                            {
                              "range": {
                                "effectiveDate": {
                                  "gte": 1543982400,
                                  "lt": 1575518400
                                }
                              }
                            }
                          ]
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        }
      },
      "size": 0,
      "aggs": {
        "by_id": {
          "composite": {
            "sources": [
              {
                "agg_on_id": {
                  "terms": {
                    "field": "id"
                  }
                }
              }
            ],
            "size": 10000,
            "after": {
              "agg_on_id": -1
            }
          },
          "aggs": {
            "latest_snapshot": {
              "top_hits": {
                "sort": [
                  {
                    "effectiveDate": "desc"
                  }
                ],
                "_source": true,
                "size": 1
              }
            }
          }
        }
      }
    }
  </code></pre>
  
  <p>It first creates a query (similar to above) for a first trip to Elasticsearch to extract some info ('links') needed for building this query. 
  Each trip to Elasticsearch may return millions of results, so it does paging using the "search_after" mechanism.
  I need to convert this POC to a Spring application.</p>
  
  <p><strong>Question</strong>: Which one is most appropriate for this case - Spring Data Elasticsearch or Elasticsearch Java High Level REST Client? 
  Spring data elasticsearch seems to do a good job at creating simple queries without much effort, but would it help me in this case?
  Any suggestions are be much appreciated.
  Thanks!</p>