diff --git a/lib/elastic_search_helper.rb b/lib/elastic_search_helper.rb index 286dbc1..cf24423 100644 --- a/lib/elastic_search_helper.rb +++ b/lib/elastic_search_helper.rb @@ -14,29 +14,21 @@ class ElasticSearchHelper response = RestClient::Request.execute( method: :put, url: "#{server_uri}/#{index}", - header: header + headers: header, payload: self.mappings.to_json) end def mappings { - "mappings": { + "mappings": { "_doc": { - "properties": { - "type": { "type": 'keyword' }, - "paste_metadata": { "type": 'nested' }, - "properties": [{ - "scrape_url": { "type": 'string' }, - "full_url": { "type": 'string' }, - "date": { "type": 'string' }, - "size": { "type": 'string' }, - "expire": { "type": 'string' }, - "title": { "type": 'string' }, - "syntax": { "type": 'string' }, - "user": { "type": 'string' }, - "hits": { "type": 'string' } - }], - "paste_text": { "type": 'string' } + "properties": { + "paste_metadata": { + "type": "nested" + }, + "paste_text": { + "type": "text" + } } } } @@ -63,7 +55,7 @@ class ElasticSearchHelper def json_to_es_bulk(array_of_paste_json) array_of_paste_json.each do |paste_json| - self.to_es(paste_json) + self.json_to_es(paste_json) end end diff --git a/lib/es.rb b/lib/es.rb deleted file mode 100644 index 124ab6e..0000000 --- a/lib/es.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'elasticsearch' - -client = Elasticsearch::Client.new url: 'http://192.168.1.9200', log: true - -client.transport.reload_connections! - -client.cluster.health - -client.index index: 'paste', type: 'pastes' diff --git a/lib/mappings.json b/lib/mappings.json new file mode 100644 index 0000000..c758ffd --- /dev/null +++ b/lib/mappings.json @@ -0,0 +1,12 @@ + { + "mappings": { + "_doc": { + "properties": { + "paste_metadata": { + "type": "nested" + }, + "paste_text": { "type": "text" } + } + } + } + }