---
# System prepended metadata

title: Untitled

---

### Creacion del indice

**TODO:** No sé si alguien sabe como manejar la siguiente situación:
- Se crea el mapping del indice
- Se inserta el primer  -tweet- (y se mapean nuevos campos de forma automática)
- Luego se inserta otro tweet pero este tiene algún campo extra que el anterior no tenia y entonces se produce un error al no estar mapeado.
- Quizás haya que mapear a mano todos los campos de la estructura de los tweets?

```json=
PUT /g20
{
  "settings": {
    "analysis": {
      "analyzer": {
        "htmlStripAnalyzer": {
          "type": "custom",
          "tokenizer": "keyword",
          "char_filter": [
            "html_strip"
          ]
        },
        "textAnalyzer": {
          "type": "custom", 
          "char_filter": [
              "html_strip"
          ], 
          "tokenizer": "standard",
          "filter": [
            "stop", 
            "snowball"
          ]  
        }
      }
    }
  },
  "mappings": {
      "properties": {
        "text": {
          "type": "text",
          "analyzer": "textAnalyzer"
        },
        "user.created_at": {
          "type": "date",
          "format": "EEE MMM dd HH:mm:ss Z yyyy"
        },
        "id": {
          "type": "long"
        },
        "user.location": {
          "type": "keyword"
        },
        "user.followers_count": {
          "type": "long"
        },
        "place.bounding_box": {
          "type": "geo_shape",
          "coerce": true,
          "ignore_malformed": true
        },
        "source": {
          "type": "text",
          "analyzer": "htmlStripAnalyzer"
        },
        "entities.hashtags": {
          "type": "keyword"
        },
        "timestamp_ms": {
          "type": "date"
        },
        "retweeted": {
          "type": "boolean"
        }
      }
  }
}
```

### Insertar un registro
```json
POST /g20test/_doc/1
{
   "quote_count":0,
   "contributors":null,
   "truncated":true,
   "text":"@WhiteHouse He  continued with Obama's turn around economy. Obama didnt overturn environmental laws &amp;\nClimate chang\u2026 https://t.co/oRP4fRkWlJ",
   "is_quote_status":false,
   "in_reply_to_status_id":1059614092254683136,
   "reply_count":0,
   "id":1059865023755894784,
   "favorite_count":0,
   "entities":{
      "user_mentions":[
         {
            "id":822215673812119553,
            "indices":[
               0,
               11
            ],
            "id_str":"822215673812119553",
            "screen_name":"WhiteHouse",
            "name":"The White House"
         }
      ],
      "symbols":[
         
      ],
      "hashtags":[
         
      ],
      "urls":[
         {
            "url":"https://t.co/oRP4fRkWlJ",
            "indices":[
               121,
               144
            ],
            "expanded_url":"https://twitter.com/i/web/status/1059865023755894784",
            "display_url":"twitter.com/i/web/status/1\u2026"
         }
      ]
   },
   "retweeted":false,
   "coordinates":null,
   "timestamp_ms":"1541526487660",
   "source":"<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>",
   "in_reply_to_screen_name":"WhiteHouse",
   "id_str":"1059865023755894784",
   "display_text_range":[
      12,
      140
   ],
   "retweet_count":0,
   "in_reply_to_user_id":822215673812119553,
   "favorited":false,
   "user":{
      "follow_request_sent":null,
      "profile_use_background_image":true,
      "default_profile_image":false,
      "id":950552286605946880,
      "default_profile":true,
      "verified":false,
      "profile_image_url_https":"https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png",
      "profile_sidebar_fill_color":"DDEEF6",
      "profile_text_color":"333333",
      "followers_count":5,
      "profile_sidebar_border_color":"C0DEED",
      "id_str":"950552286605946880",
      "profile_background_color":"F5F8FA",
      "listed_count":0,
      "profile_background_image_url_https":"",
      "utc_offset":null,
      "statuses_count":551,
      "description":null,
      "friends_count":93,
      "location":null,
      "profile_link_color":"1DA1F2",
      "profile_image_url":"http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png",
      "following":null,
      "geo_enabled":true,
      "profile_background_image_url":"",
      "name":"Robert shuster",
      "lang":"en",
      "profile_background_tile":false,
      "favourites_count":11,
      "screen_name":"Robertshuster8",
      "notifications":null,
      "url":null,
      "created_at":"Tue Jan 09 02:18:20 +0000 2018",
      "contributors_enabled":false,
      "time_zone":null,
      "protected":false,
      "translator_type":"none",
      "is_translator":false
   },
   "geo":null,
   "in_reply_to_user_id_str":"822215673812119553",
   "lang":"en",
   "extended_tweet":{
      "display_text_range":[
         12,
         178
      ],
      "entities":{
         "user_mentions":[
            {
               "id":822215673812119553,
               "indices":[
                  0,
                  11
               ],
               "id_str":"822215673812119553",
               "screen_name":"WhiteHouse",
               "name":"The White House"
            }
         ],
         "symbols":[
            
         ],
         "hashtags":[
            
         ],
         "urls":[
            
         ]
      },
      "full_text":"@WhiteHouse He  continued with Obama's turn around economy. Obama didnt overturn environmental laws &amp;\nClimate change. And trump blew up\nOur biggest budget deficit in history."
   },
   "created_at":"Tue Nov 06 17:48:07 +0000 2018",
   "filter_level":"low",
   "in_reply_to_status_id_str":"1059614092254683136",
   "place":{
      "country_code":"US",
      "url":"https://api.twitter.com/1.1/geo/id/3b77caf94bfc81fe.json",
      "country":"United States",
      "place_type":"city",
      "bounding_box":{
         "type":"Polygon",
         "coordinates":[
            [
               [
                  -118.668404,
                  33.704538
               ],
               [
                  -118.668404,
                  34.337041
               ],
               [
                  -118.155409,
                  34.337041
               ],
               [
                  -118.155409,
                  33.704538
               ]
            ]
         ]
      },
      "full_name":"Los Angeles, CA",
      "attributes":{
         
      },
      "id":"3b77caf94bfc81fe",
      "name":"Los Angeles"
   }
}
```


### Busqueda generica
```json
GET /g20test/_search
{
  "query": {
    "match_all": {}
  }
}
```

Referencias:
- [All About Analyzers, Part One](https://www.elastic.co/es/blog/found-text-analysis-part-1)
- [Snowball (stemmer)](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-snowball-tokenfilter.html)



