0

I have an sql query like

select student_name,roll_number 
from
mytable
where
(course = 'CCNA' or course = 'MCSE') and course NOT Like '%network%'

How can i create an equivalent nested boolean query in elasticsearch?

4
  • Refer bool-query: elastic.co/guide/en/elasticsearch/reference/current/… Commented Apr 3, 2018 at 16:37
  • How do I include or criteria here? Commented Apr 3, 2018 at 16:40
  • have you tried terms query? Commented Apr 3, 2018 at 16:42
  • You may also try the should part of the bool query. Commented Apr 3, 2018 at 19:06

1 Answer 1

2

Below query might help you, This query responds with records which course does not contain a "network" keyword and course has a value "ccna" or "mcse". I have not considered a case sensitiveness feature here and assumed that you have a default mapping.

POST study-doc*/_search
{
"query": {
    "bool": {
        "must": [
           {
               "bool": {
                   "should": [
                      {
                          "term": {
                             "course": {
                                "value": "ccna"
                             }
                          }
                      },{
                          "term": {
                             "course": {
                                "value": "msce"
                             }
                          }
                      }
                   ]
               }},
               {
               "bool": {
                    "must": [
                       {
                           "wildcard": {
                              "course.keyword": {
                                 "value": "^((?!network).)*$"
                              }
                           }
                       }
                    ]    
               }
           }

        ]
    }
}
}
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.