0

I have an Elastic Search Query in JSON format (mentioned below) that I'm reading from a database and I will have to update this query in a Java spring program. How do I convert the JSON query object to a QueryBuilder object so that I can manipulate it before executing it to get the hits?

{
  "query": {
    "bool": {
      "must_not": [
        {
          "match": {
            "after.values": {
              "query": "Beach Soccer",
              "operator": "and"
            }
          }
        },
        {
          "match": {
            "after.values": {
              "query": "Football",
              "operator": "and"
            }
          }
        }
      ],
      "should": [
        {
          "match": {
            "after.values": "Australian Open"
          }
        },
        {
          "match": {
            "after.values": "Golf Austra"
          }
        },
        {
          "match": {
            "after.values": "Australasia"
          }
        }
      ]
    }
  }
}

Same problem as How to construct QueryBuilder from JSON DSL when using Java API in ElasticSearch?

But the solution selected as answer there no longer works. I have the exact same problem as @armstrongya in 2021 and doing QueryBuilders.wrapperQuery(jsonQueryString); is not cutting it for me.

This is what I get :

{ "wrapper" : { "query" : "eyJib29sIjp7Im11c3Rfbm90IjpbeyJtYXRjaCI6eyJhZnRlci50aXRsZSI6eyJxdWVyeSI6IldpbWJlbGRvbiIsIm9wZXJhdG9yIjoiYW5kIn19fSx7Im1hdGNoIjp7ImZpZWxkLmRlc2NyaXB0aW9uIjp7InF1ZXJ5IjoiV2ltYmVsZG9uIiwib3BlcmF0b3IiOiJhbmQifX19LHsibWF0Y2giOnsiYWZ0ZXIudGl0bGUiOnsicXVlcnkiOiJXVEEiLCJvcGVyYXRvciI6ImFuZCJ9fX0seyJtYXRjaCI6eyJmaWVsZC5kZXNjcmlwdGlvbiI6eyJxdWVyeSI6IldUQSIsIm9wZXJhdG9yIjoiYW5kIn19fV19fQ==" }

1 Answer 1

0

I answered my own question: This helped :Elasticsearch Jest client add condition to json query

Mainly, I just realized that I was having the proper query I needed all along, it was just being decoded in base64 encoding. (eyJib29sIjp7Im11c3Rfbm90IjpbeyJtYXRjaCI6eyJhZnRlci50aXRsZSI6eyJxdWVyeSI6IldpbWJlbGRvbiIsIm9wZXJhdG9yIjoiYW5kIn19fSx7Im1hdGNoIjp7ImZpZWxkLmRlc2NyaXB0aW9uIjp7InF1ZXJ5IjoiV2ltYmVsZG9uIiwib3BlcmF0b3IiOiJhbmQifX19LHsibWF0Y2giOnsiYWZ0ZXIudGl0bGUiOnsicXVlcnkiOiJXVEEiLCJvcGVyYXRvciI6ImFuZCJ9fX0seyJtYXRjaCI6eyJmaWVsZC5kZXNjcmlwdGlvbiI6eyJxdWVyeSI6IldUQSIsIm9wZXJhdG9yIjoiYW5kIn19fV19fQ==)

I used an online base64 decoder to reveal the "pretty" decoded version of the query.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.