Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. # ** EXAM OBJECTIVES: MAPPINGS AND TEXT ANALYSIS **
  2. # (remove, if present, any `hamlet*` index and index template)
  3. # Create the index `hamlet_1`, with one primary shard and no replicas
  4. # Define the mapping for `hamlet_1`, satisfying the following criteria: (i) has a type "_doc" with three string fields named `speaker`, `line_number`, and `text_entry`; (ii) only `text_entry` is analysed; (iii) `text_entry` has a multi-field named `english`, associated with the built-in "english" analyzer; (iv) no aggregations supported by `line_number`
  5. # Populate `hamlet_1` by running the _bulk command with the request-body below
  6. {"index":{"_index":"hamlet_1","_id":0}}
  7. {"line_number":"1.1.1","speaker":"BERNARDO","text_entry":"Whos there?"}
  8. {"index":{"_index":"hamlet_1","_id":1}}
  9. {"line_number":"1.1.2","speaker":"FRANCISCO","text_entry":"Nay, answer me: stand, and unfold yourself."}
  10. {"index":{"_index":"hamlet_1","_id":2}}
  11. {"line_number":"1.1.3","speaker":"BERNARDO","text_entry":"Long live the king!"}
  12. {"index":{"_index":"hamlet_1","_id":3}}
  13. {"line_number":"1.2.1","speaker":"KING CLAUDIUS","text_entry":"Though yet of Hamlet our dear brothers death"}
  14. {"index":{"_index":"hamlet_1","_id":4}}
  15. {"line_number":"1.2.2","speaker":"KING CLAUDIUS","text_entry":"The memory be green, and that it us befitted"}
  16. {"index":{"_index":"hamlet_1","_id":5}}
  17. {"line_number":"1.3.1","speaker":"LAERTES","text_entry":"My necessaries are embarkd: farewell:"}
  18. {"index":{"_index":"hamlet_1","_id":6}}
  19. {"line_number":"1.3.4","speaker":"LAERTES","text_entry":"But let me hear from you."}
  20. {"index":{"_index":"hamlet_1","_id":7}}
  21. {"line_number":"1.3.5","speaker":"OPHELIA","text_entry":"Do you doubt that?"}
  22. {"index":{"_index":"hamlet_1","_id":8}}
  23. {"line_number":"1.4.1","speaker":"HAMLET","text_entry":"The air bites shrewdly; it is very cold."}
  24. {"index":{"_index":"hamlet_1","_id":9}}
  25. # Create the index `hamlet_2`, which updates the mapping of `hamlet_1` by defining a multi-field for `speaker`. Such multi-field is named `token` and it maps to a (default) analysed text
  26. # Reindex `hamlet_1` into `hamlet_2`
  27. # Verify that full-text queries on "speaker.token" are enabled on `hamlet_2`
  28. # Index more documents in `hamlet_2` by running the _bulk command with the request-body below
  29. {"index":{"_index":"hamlet_2","_id":"p1"}}
  30. {"name":"HAMLET","relationship":[{"name":"HORATIO","type":"friend"},{"name":"GERTRUDE","type":"mother"}]}
  31. {"index":{"_index":"hamlet_2","_id":"p2"}}
  32. {"name":"KING CLAUDIUS","relationship":[{"name":"HAMLET","type":"nephew"}]}
  33. # The items of the `relationship` array cannot be searched independently. For example, the query below returns 1 hit
  34. GET hamlet_2/_search
  35. {
  36. "query": {
  37. "bool": {
  38. "must": [
  39. { "match": { "relationship.name": "gertrude" } },
  40. { "match": { "relationship.type": "friend" } }
  41. ]
  42. }
  43. }
  44. }
  45. # Create the index `hamlet_3`, which updates the mapping of `hamlet_2` by satisfying the following criteria: (i) the inner objects of `relationship` can be searched independently; (ii) the fields of the inner objects of `relationship` are all keywords type
  46. # Reindex `hamlet_2` into `hamlet_3`
  47. # Verify that the items in `relationship` can be searched independently of each other. For example, the query below should return 0 hits
  48. GET hamlet_3/_search
  49. {
  50. "query": {
  51. "nested": {
  52. "path": "relationship",
  53. "query": {
  54. "bool": {
  55. "must": [
  56. { "match": { "relationship.name": "GERTRUDE" } },
  57. { "match": { "relationship.type": "friend" } }
  58. ]
  59. }
  60. }
  61. }
  62. }
  63. }
  64. # Change the value of `relationship.type` in the query above to get 1 hit
  65. # So far, we have indexed two kinds of documents, either related to a character or to the dialogue. Notice that a profile-related document can be linked to many dialogue-related documents. We will model this one-to-many relation in the next step
  66. # Create the index `hamlet_4`, which updates the mapping of `hamlet_3` by satisfying the following criteria: (i) has a join field named `profile_or_dialogue`; (ii) such join field defines a parent/child relation between a `profile` and a `dialogue`, respectively
  67. # Reindex `hamlet_3` into `hamlet_4`
  68. # Update the document with id "p2" (i.e., the profile document of King Claudius) by adding the field `profile_or_dialogue` and setting its property `name` to "profile"
  69. # To be continued
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement