Guest User

Untitled

a guest
Nov 2nd, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. # CREATE INDEX
  2. curl -X POST 'http://localhost:9200/bands/' -d '{
  3. "mappings" : {
  4. "documents" : {
  5. "properties" : {
  6. "title" : {
  7. "type" : "string"
  8. },
  9. "year" : {
  10. "type" : "integer"
  11. },
  12. "xref" : {
  13. "type" : "nested",
  14. "properties" : {
  15. "name" : {
  16. "type" : "string"
  17. }
  18. }
  19. }
  20. }
  21. }
  22. }
  23. }'
  24.  
  25. # ADD DOCUMENT
  26. curl -X PUT 'http://localhost:9200/bands/documents/1' -d '
  27. {
  28. "title" : "Pink Floyd",
  29. "year" : "1965",
  30. "xref" : [
  31. {
  32. "name" : "Syd Barrett"
  33. },
  34. {
  35. "name" : "Roger Waters"
  36. },
  37. {
  38. "name" : "David Gilmour"
  39. },
  40. {
  41. "name" : "Nick Mason"
  42. },
  43. {
  44. "name" : "Roger Waters"
  45. }
  46. ]
  47. }'
  48.  
  49. # SEARCH DOCUMENT
  50. curl -XGET "http://localhost:9200/bands/documents/_search?pretty=true" -d '
  51. {
  52. "query" : {
  53. "nested" : {
  54. "path" : "xref",
  55. "query" : {
  56. "bool" : {
  57. "must" : [
  58. { "match" : { "xref.name" : "Roger" } }
  59. ]
  60. }
  61. }
  62. }
  63. },
  64. "fields" : [
  65. "title"
  66. ]
  67. }'
  68.  
  69. # RESULTS / NO PROBLEM
  70. {
  71. "took" : 1,
  72. "timed_out" : false,
  73. "_shards" : {
  74. "total" : 5,
  75. "successful" : 5,
  76. "failed" : 0
  77. },
  78. "hits" : {
  79. "total" : 1,
  80. "max_score" : 1.058217,
  81. "hits" : [ {
  82. "_index" : "bands",
  83. "_type" : "documents",
  84. "_id" : "1",
  85. "_score" : 1.058217,
  86. "fields" : {
  87. "title" : [ "Pink Floyd" ]
  88. }
  89. } ]
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment