Skip to content

omurbekjk/convert-dsl-to-es-query-with-antlr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

convert-dsl-to-es-query-with-antlr

Convert custom sql like dsl query to es query

Basic example 1:

input: "price=2000"

Output:

{
  "bool": {
    "must": {
      "term": {
        "price": "2000"
      }
    }
  }
}

Basic example 2:

input: "price=2000 AND year=2021"

Output:

{
  "bool": {
    "must": [
      {
        "bool": {
          "must": {
            "term": {
              "year": "2021"
            }
          }
        }
      },
      {
        "bool": {
          "must": {
            "term": {
              "price": "2000"
            }
          }
        }
      }
    ]
  }
}

Complex example 1:

input: "price=2000 AND year=2021 OR color=\"red\" OR (model=\"Tesla\")"

Output:

{
  "bool": {
    "should": [
      {
        "bool": {
          "must": {
            "term": {
              "model": "Tesla"
            }
          }
        }
      },
      {
        "bool": {
          "should": [
            {
              "bool": {
                "must": {
                  "term": {
                    "color": "red"
                  }
                }
              }
            },
            {
              "bool": {
                "must": [
                  {
                    "bool": {
                      "must": {
                        "term": {
                          "year": "2021"
                        }
                      }
                    }
                  },
                  {
                    "bool": {
                      "must": {
                        "term": {
                          "price": "2000"
                        }
                      }
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    ]
  }
}

Any questions/bugs feel free to open an issue.

About

Convert custom sql like dsl query to es query

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published