1

I'd like to "translate" a string like:

A AND (C OR B) AND NOT D

into an Elasticsearch query like:

{
  "query": {
    "bool": {
      "must": {
        "term": {
          "text": "A"
        }
      },
      "must_not": {
        "term": {
          "text": "D"
        }
      },
      "should": [
        {
          "term": {
            "text": "B"
          }
        },
        {
          "term": {
            "text": "C"
          }
        }
      ],
      "minimum_should_match": 1,
      "boost": 1
    }
  }
}

does exists some library which I can use ? any help appreciated

Thanks!

5
  • Note that A AND (C OR B) AND NOT D is a valid query (Lucene expression syntax) when used inside a query_string query and is translated internally by ES to the second query you showed. Commented May 11, 2018 at 9:25
  • You mean this elastic.co/guide/en/elasticsearch/reference/current/… ? thanks! Going to read it Commented May 11, 2018 at 9:26
  • Yes, exactly that. Commented May 11, 2018 at 9:31
  • works fine, thanks! Commented May 11, 2018 at 9:37
  • Awesome, glad that was helpful! Commented May 11, 2018 at 9:41

1 Answer 1

1

ok according to:

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html

I can do query like:

{
    "query": {
        "query_string" : {
            "default_field" : "text",
            "query" : (this AND (submitted OR flowers) AND NOT blight"
        }
    }
}

which works great.

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.