Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Create Index With A Document, And A Number
- POST testiamgreengang/_doc
- {
- "message": "boo",
- "number": 1
- }
- Get All Settings/Mappings/Aliases
- GET testiamgreengang
- Just Get Aliases
- GET testiamgreengang/_alias
- Just Get Mappings
- GET testiamgreengang/_mapping
- Just Get Settings
- GET testiamgreengang/_settings
- Create An Index Only No Mapping
- PUT testiamgreengang2
- See No Mappings Defined
- GET testiamgreengang2
- Put A Doc In It
- POST testiamgreengang2/_doc
- {
- "number": 1
- }
- GET testiamgreengang2/_mapping
- See An Error
- POST testiamgreengang2/_doc
- {
- "number": "this Will Give an Error"
- }
- This Gives An Error As Well ((<<_doc Is Missing)
- POST testiamgreengang2/
- {
- "number": "1"
- }
- End copying
- When you create the document you will get this:
- {
- "_index" : "testiamgreengang",
- "_type" : "_doc", "_id" : "xnY40m4Bsn0230I3dXqj",
- "_version" : 1,
- "result" : "created",
- "_shards" : {
- "total" : 2,
- "successful" : 2,
- "failed" : 0
- },
- "_seq_no" : 1,
- "_primary_term" : 1
- }
- 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)
- Lets get all the settings:
- {
- "testiamgreengang" : {
- "aliases" : { },
- "mappings" : {
- "properties" : {
- "message" : {
- "type" : "text",
- "fields" : {
- "keyword" : {
- "type" : "keyword",
- "ignore_above" : 256
- }
- }
- },
- "number" : { "type" : "long" }
- }
- },
- "settings" : {
- "index" : {
- "creation_date" : "1575484402559",
- "number_of_shards" : "1",
- "number_of_replicas" : "1",
- "uuid" : "2eSFzwLcRpG4v2c4c5ORLg",
- "version" : { "created" : "7050099" },
- "provided_name" : "testiamgreengang"
- }
- }
- }
- }
- 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.
- Let's dive into the mapping:
- {
- "testiamgreengang" : { <<index name
- "mappings" : { <<<Older versions would have a type above this level, types are being removed
- "properties" : { <<standard
- "message" : { <<field name
- "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)
- "fields" : {
- "keyword" : {
- "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)
- "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
- }
- }
- },
- "number" : { << field name
- "type" : "long" << number field like you would see in any numerical variable
- }
- }
- }
- }
- }
- The settings:
- GET testiamgreengang/_settings
- {
- "testiamgreengang" : {
- <<Index name>> "settings" : { <<Settings subsection>>
- "index" : { <<Index subsection of Settings>>
- "creation_date" : "1575484402559",
- "number_of_shards" : "1", <<Can't be changed normally without being reindexed>>
- "number_of_replicas" : "1", <<<Can be changed dynamically, changing it to 0 or 1, or 35 (Don't recommend 35>>
- "uuid" : "2eSFzwLcRpG4v2c4c5ORLg" <<uuid of the index>>,
- "version" : { "created" : "7050099" },
- "provided_name" : "testiamgreengang"
- }
- }
- }
- }
- Fun with the analyzer: https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-standard-analyzer.html
- POST _analyze { "analyzer": "standard", "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone." }
- 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
- 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.
- 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