Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. Create Index With A Document, And A Number
  2. POST testiamgreengang/_doc
  3. {
  4. "message": "boo",
  5. "number": 1
  6. }
  7.  
  8. Get All Settings/Mappings/Aliases
  9. GET testiamgreengang
  10.  
  11. Just Get Aliases
  12. GET testiamgreengang/_alias
  13.  
  14. Just Get Mappings
  15. GET testiamgreengang/_mapping
  16.  
  17. Just Get Settings
  18. GET testiamgreengang/_settings
  19.  
  20. Create An Index Only No Mapping
  21. PUT testiamgreengang2
  22.  
  23. See No Mappings Defined
  24. GET testiamgreengang2
  25.  
  26. Put A Doc In It
  27. POST testiamgreengang2/_doc
  28. {
  29. "number": 1
  30. }
  31.  
  32. GET testiamgreengang2/_mapping
  33.  
  34. See An Error
  35. POST testiamgreengang2/_doc
  36. {
  37. "number": "this Will Give an Error"
  38. }
  39.  
  40. This Gives An Error As Well ((<<_doc Is Missing)
  41. POST testiamgreengang2/
  42. {
  43. "number": "1"
  44. }
  45.  
  46. End copying
  47.  
  48. When you create the document you will get this:
  49.  
  50. {
  51. "_index" : "testiamgreengang",
  52. "_type" : "_doc", "_id" : "xnY40m4Bsn0230I3dXqj",
  53. "_version" : 1,
  54. "result" : "created",
  55. "_shards" : {
  56. "total" : 2,
  57. "successful" : 2,
  58. "failed" : 0
  59. },
  60. "_seq_no" : 1,
  61. "_primary_term" : 1
  62. }
  63.  
  64. This says that it updated the shards (Primary and replica) with the document ID shown, (FYI you can fetch a specific document like this: GET testiamgreengang/_doc/xnY40m4Bsn0230I3dXqj ) <<<That id will be different if you do this, it will be showed to you)
  65.  
  66. Lets get all the settings:
  67. {
  68. "testiamgreengang" : {
  69. "aliases" : { },
  70. "mappings" : {
  71. "properties" : {
  72. "message" : {
  73. "type" : "text",
  74. "fields" : {
  75. "keyword" : {
  76. "type" : "keyword",
  77. "ignore_above" : 256
  78. }
  79. }
  80. },
  81. "number" : { "type" : "long" }
  82. }
  83. },
  84. "settings" : {
  85. "index" : {
  86. "creation_date" : "1575484402559",
  87. "number_of_shards" : "1",
  88. "number_of_replicas" : "1",
  89. "uuid" : "2eSFzwLcRpG4v2c4c5ORLg",
  90. "version" : { "created" : "7050099" },
  91. "provided_name" : "testiamgreengang"
  92. }
  93. }
  94. }
  95. }
  96.  
  97. When you create an index, it will use the default dynamic detection of fields (which doesn't always work right for fields that sometimes have numbers, and sometimes have words. You must specify so it doesn't freak out.
  98.  
  99. Let's dive into the mapping:
  100. {
  101. "testiamgreengang" : { <<index name
  102. "mappings" : { <<<Older versions would have a type above this level, types are being removed
  103. "properties" : { <<standard
  104. "message" : { <<field name
  105. "type" : "text", <<This is a type text which is analyzed by the standard analyzer, which takes out stop words and makes it all lower case (You can play with this as well. I'll throw that in the bottom)
  106. "fields" : {
  107. "keyword" : {
  108. "type" : "keyword", <<This adds a separate type, which is keyword, No modification is done to the keyword, it would have to be an exact match, this is used for aggregations, and other things later on)
  109. "ignore_above" : 256 <<Keyword will ignore characters above 256, this is a good thing because some times keywords can get to be too large for lucene
  110. }
  111. }
  112. },
  113. "number" : { << field name
  114. "type" : "long" << number field like you would see in any numerical variable
  115. }
  116. }
  117. }
  118. }
  119. }
  120.  
  121. The settings:
  122. GET testiamgreengang/_settings
  123. {
  124. "testiamgreengang" : {
  125. <<Index name>> "settings" : { <<Settings subsection>>
  126. "index" : { <<Index subsection of Settings>>
  127. "creation_date" : "1575484402559",
  128. "number_of_shards" : "1", <<Can't be changed normally without being reindexed>>
  129. "number_of_replicas" : "1", <<<Can be changed dynamically, changing it to 0 or 1, or 35 (Don't recommend 35>>
  130. "uuid" : "2eSFzwLcRpG4v2c4c5ORLg" <<uuid of the index>>,
  131. "version" : { "created" : "7050099" },
  132. "provided_name" : "testiamgreengang"
  133. }
  134. }
  135. }
  136. }
  137.  
  138. Fun with the analyzer: https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-standard-analyzer.html
  139.  
  140. POST _analyze { "analyzer": "standard", "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone." }
  141.  
  142. I would recommend downloading the stack and running it locally (to play with it), or use the free cloud instance that we provide (cause its easier to immediately start doing what we've been talking about) https://www.elastic.co/blog/elasticsearch-service-on-elastic-cloud-introduces-new-pricing-with-reduced-costs#:~:targetText=Effective%20today%2C%20a%20lower%20starting,storage%20and%20data%20transfer%20costs
  143.  
  144. I forgot to mention Mapping can only be added to not changed on an existing index. So if something gets detected as a number, it can't be changed on the existing index, it would have to be reindexed.
  145.  
  146. All of the commands I sent can be run directly in curl for example: curl -u elastic -XPOST -k "https://elk1.budmanhome.local:9200/testiamgreengang/_doc" -H 'Content-Type: application/json' -d'{ "message": "boo", "number": 1}'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement