项目作者: omurbekjk

项目描述 :
Convert custom sql like dsl query to es query
高级语言: Go
项目地址: git://github.com/omurbekjk/convert-dsl-to-es-query-with-antlr.git


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

Convert custom sql like dsl query to es query

Basic example 1:

input: "price=2000"

Output:

  1. {
  2. "bool": {
  3. "must": {
  4. "term": {
  5. "price": "2000"
  6. }
  7. }
  8. }
  9. }

Basic example 2:

input: "price=2000 AND year=2021"

Output:

  1. {
  2. "bool": {
  3. "must": [
  4. {
  5. "bool": {
  6. "must": {
  7. "term": {
  8. "year": "2021"
  9. }
  10. }
  11. }
  12. },
  13. {
  14. "bool": {
  15. "must": {
  16. "term": {
  17. "price": "2000"
  18. }
  19. }
  20. }
  21. }
  22. ]
  23. }
  24. }

Complex example 1:

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

Output:

  1. {
  2. "bool": {
  3. "should": [
  4. {
  5. "bool": {
  6. "must": {
  7. "term": {
  8. "model": "Tesla"
  9. }
  10. }
  11. }
  12. },
  13. {
  14. "bool": {
  15. "should": [
  16. {
  17. "bool": {
  18. "must": {
  19. "term": {
  20. "color": "red"
  21. }
  22. }
  23. }
  24. },
  25. {
  26. "bool": {
  27. "must": [
  28. {
  29. "bool": {
  30. "must": {
  31. "term": {
  32. "year": "2021"
  33. }
  34. }
  35. }
  36. },
  37. {
  38. "bool": {
  39. "must": {
  40. "term": {
  41. "price": "2000"
  42. }
  43. }
  44. }
  45. }
  46. ]
  47. }
  48. }
  49. ]
  50. }
  51. }
  52. ]
  53. }
  54. }

Any questions/bugs feel free to open an issue.