0

My Query which returns the error: elasticsearch.exceptions.RequestError: RequestError(400, 'x_content_parse_exception', '[8:43] [bool] failed to parse field [must]')

I have tried replacing the [] with {} but that hasen't helped

    chunksize, chunk, double_chunk = ssdeep_value.split(":")
    chunksize = int(chunksize)
    twice_chunksize = chunksize*2
    half_chunksize = chunksize*0.5

    query = """
    {
        "query": {
            "bool": {
                "must": [
                    {
                        "terms": {
                            "chunksize": [chunksize, twice_chunksize, half_chunksize]
                        }
                    },
                    {
                        "bool": {
                            "should": [
                                {
                                    "match": {
                                        "chunk": {
                                            "query": chunk,
                                        }
                                    }
                                },
                                {
                                    "match": {
                                        "double_chunk": {
                                            "query": double_chunk,
                                        }
                                    }
                                }
                            ],
                            "minimum_should_match": 1
                        }
                    }
                ]
            }
        }
    }
    """

    results = es.search(index="ssdeep-index", body=query)

1 Answer 1

1

The body parameter (query in your case) is supposed to be a dictionary, not a multiline string.

So use:

query = {
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "chunksize": [chunksize, twice_chunksize, half_chunksize]
          }
        },
        {
          "bool": {
            "should": [
              {
                "match": {
                  "chunk": {
                    "query": chunk
                  }
                }
              },
              {
                "match": {
                  "double_chunk": {
                    "query": double_chunk
                  }
                }
              }
            ],
            "minimum_should_match": 1
          }
        }
      ]
    }
  }
}

results = es.search(index="ssdeep-index", body=query)
Sign up to request clarification or add additional context in comments.

1 Comment

You are god-sent. Thank you again!

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.