Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. select res.id as 'res.id', res.name as 'res.name', tag.name as 'tag.name'
  2. from Res res, ResTags rt, Tags tag
  3. where res.id *= rt.resrow and rt.tagid *= tag.id
  4.  
  5. res.id | res.name | tag.name
  6. 0 | result0 | null
  7. 0 | result0 | tagA
  8. 1 | result1 | tagA
  9. 1 | result1 | tagB
  10. 2 | result2 | tagA
  11. 2 | result2 | tagC
  12.  
  13. {
  14. "mappings": {
  15. "res": {
  16. "properties": {
  17. "id": { "type": "long"},
  18. "name": { "type": "string" },
  19. "tags": {
  20. "type": "nested",
  21. "properties": { "tagname": { "type": "string" }}
  22. }
  23. }
  24. }
  25. }
  26.  
  27. input {
  28. jdbc {
  29. jdbc_driver_library => "jtds-1.3.1.jar"
  30. jdbc_driver_class => "Java::net.sourceforge.jtds.jdbc.Driver"
  31. jdbc_connection_string => "jdbc:jtds:sybase://hostname.com:1234/schema"
  32. jdbc_user => "george"
  33. jdbc_password => "monkey"
  34. jdbc_fetch_size => 100
  35. statement_filepath => "/home/george/sql"
  36. }
  37. }
  38. output {
  39. elasticsearch {
  40. action => "update"
  41. index => "myres"
  42. document_type => "res"
  43. document_id => "%{res.id}"
  44. script_lang => "groovy"
  45. hosts => [ "my.other.host.com:5921" ]
  46. upsert => ' {
  47. "id" : %{res.id},
  48. "name" : "%{res.name}",
  49. "tags" :[{ "tagname": "%{tag.name}" }]
  50. }'
  51. script => '
  52. if (ctx._source.res.tags.containsValue(null)) {
  53. // if null has been added replace it with actual value
  54. cts._source.res.tags = [{"tagname": "%{tag.name}" }];
  55. else {
  56. // if you find the tag, then do nothing
  57. if (ctx._source.res.tags.containsValue("%{tag.name}")) {}
  58. else {
  59. // if the value you try to add is not null
  60. if (%{tag.name} != null)
  61. // add it as a new object into the tag array
  62. ctx._source.res.tags += {"tagname": "%{tag.name}"};
  63. }
  64. }
  65. '
  66. }
  67. }
  68.  
  69. {
  70. "hits": {
  71. "total": 3,
  72. "max_score": 1,
  73. "hits": [ {
  74. "_index": "myres",
  75. "_type": "res",
  76. "_id": 0,
  77. "_score": 1,
  78. "_source": {
  79. "res": {
  80. "id":0,
  81. "name": "result0",
  82. "tags": [{"tagname": "tagA"}],
  83. "@version": "2",
  84. "@timestamp": "2016-xx-yy..."
  85. }
  86. },{
  87. "_index": "myres",
  88. "_type": "res",
  89. "_id": 1,
  90. "_score": 1,
  91. "_source": {
  92. "res": {
  93. "id":1,
  94. "name": "result1",
  95. "tags": [{"tagname": "tagA"},{"tagname": "tagB"}],
  96. "@version": "2",
  97. "@timestamp": "2016-xx-yy..."
  98. }
  99. }{
  100. "_index": "myres",
  101. "_type": "res",
  102. "_id": 2,
  103. "_score": 1,
  104. "_source": {
  105. "res": {
  106. "id":2,
  107. "name": "result2",
  108. "tags": [{"tagname": "tagA"},{"tagname": "tagC"],
  109. "@version": "2",
  110. "@timestamp": "2016-xx-yy..."
  111. }
  112. }
  113. }
  114. ...
  115.  
  116. [400] {"error":"ActionRequestValidationException[Validation Failed:
  117. 1: script or doc is missing;
  118. 2: script or doc is missing;
  119. 3: script or doc is missing;],"status":400]} {:class=> ... bla bla ...}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement