专栏:ElasticSearch、Kibana等相关技术点

index

  1. PUT /log_index_prod_a
  2. {
  3. "mappings": {
  4. "properties": {
  5. "id": {
  6. "type": "keyword"
  7. },
  8. "logLevel": {
  9. "type": "keyword"
  10. },
  11. "logTime": {
  12. "type": "date"
  13. },
  14. "userId": {
  15. "type": "long"
  16. },
  17. "ip": {
  18. "type": "ip"
  19. },
  20. "source": {
  21. "type": "byte"
  22. },
  23. "content": {
  24. "type": "object"
  25. }
  26. }
  27. },
  28. "aliases": {
  29. "log_index_prod_alias": {}
  30. }
  31. }

template

  1. GET _template/log_index_template
  2. PUT /_template/log_index_template
  3. {
  4. "index_patterns": "log_index_prod_*",
  5. "order": 1,
  6. "mappings": {
  7. "properties": {
  8. "logLevel": {
  9. "type": "keyword"
  10. },
  11. "logTime": {
  12. "type": "date"
  13. },
  14. "userId": {
  15. "type": "long"
  16. },
  17. "ip": {
  18. "type": "ip"
  19. },
  20. "source": {
  21. "type": "byte"
  22. },
  23. "content": {
  24. "type": "object"
  25. }
  26. }
  27. },
  28. "aliases": {
  29. "log_index_prod_alias": {}
  30. }
  31. }

mapping

“content”: {“type”: “object”}会生成fields-keyword,无论插入的content.details、content.operationType的值是keyword抑或text(有空格)。

  1. GET log_index_prod_a/_mapping
  2. {
  3. "log_index_prod_a" : {
  4. "mappings" : {
  5. "properties" : {
  6. "content" : {
  7. "properties" : {
  8. "details" : {
  9. "type" : "text",
  10. "fields" : {
  11. "keyword" : {
  12. "type" : "keyword",
  13. "ignore_above" : 256
  14. }
  15. }
  16. },
  17. "category" : {
  18. "type" : "text",
  19. "fields" : {
  20. "keyword" : {
  21. "type" : "keyword",
  22. "ignore_above" : 256
  23. }
  24. }
  25. },
  26. "testArray" : {
  27. "properties" : {
  28. "foo" : {
  29. "type" : "long"
  30. }
  31. }
  32. },
  33. "testNo" : {
  34. "type" : "long"
  35. }
  36. }
  37. },
  38. "ip" : {
  39. "type" : "ip"
  40. },
  41. "logLevel" : {
  42. "type" : "keyword"
  43. },
  44. "logTime" : {
  45. "type" : "date"
  46. },
  47. "source" : {
  48. "type" : "byte"
  49. },
  50. "userId" : {
  51. "type" : "long"
  52. }
  53. }
  54. }
  55. }
  56. }

search

  1. GET _search
  2. {
  3. "query": {
  4. "match_all": {}
  5. }
  6. }
  7. GET log_index_prod_alias/_search
  8. GET log_index_prod_alias/_search
  9. {
  10. "query": {
  11. "match_all": {}
  12. },
  13. "sort": [
  14. {
  15. "logTime": {
  16. "order": "desc"
  17. }
  18. }
  19. ]
  20. }
  21. GET log_index_prod_alias/_search
  22. {
  23. "query": {
  24. "match": {
  25. "content.details": "current"
  26. }
  27. }
  28. }
  29. GET log_index_prod_alias/_search
  30. {
  31. "query": {
  32. "match": {
  33. "content.category": "sport"
  34. }
  35. }
  36. }
  37. GET log_index_prod_alias/_search
  38. {
  39. "query": {
  40. "match": {
  41. "content.category.keyword": "sport"
  42. }
  43. }
  44. }
  45. GET log_index_prod_alias/_search
  46. {
  47. "query": {
  48. "match": {
  49. "content.testNo": 1
  50. }
  51. }
  52. }
  53. GET log_index_prod_alias/_search
  54. {
  55. "query": {
  56. "match": {
  57. "userId": 1
  58. }
  59. }
  60. }