2015-03-20 4 views
3

Как я могу хранить исходные значения для всех свойств в elasticsearch?Как сохранить исходные значения для всех свойств?

Мне нужны исходные значения для агрегации, свойства неизвестны a-priory.

Update:

Хотите все свойства быть

{ 
    "type": "string", 
    "fields": { 
     "raw": { 
      "type": "string", 
      "index": "not_analyzed" 
     } 
    } 
} 

Принимая во внимание свойства являются динамическими

Спасибо заранее.

ответ

0
You have to use PUT method to add data to elasticsearch. 

Example: 

`$ curl -XPUT 'http://localhost:9200/products/product/123' -d '{ 
    "ProductID": 123, 
    "SellingPrice": 1200.00, 
    "DiscountAmount":0.00, 
    "Discount": { 
    "Type": "percentage", 
    "Amount": 25, 
    "StartDate": "2014-08-13T12:05:00", 
    "EndDate": "2014-12-31T12:10:00" 
    } 
}'` 

CURL library can be used to send data to your elasticsearch. For testing purpose you can use [chrome sense plugin][1]. 

For getting aggregation use POST or GET method. 

Example: 

`$ curl -XGET 'http://localhost:9200/products/product/_search?search_type=count' -d '{ 
    "aggregations": { 
    "my_agg": { 
     "terms": { 
     "field": "SellingPrice" 
     } 
    } 
    } 
} 
'` 

Above example will return aggregation result as below: 

`{ 
    "took": 48, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 117, 
     "max_score": 0, 
     "hits": [] 
    }, 
    "aggregations": { 
     "my_agg": { 
     "doc_count_error_upper_bound": 0, 
     "sum_other_doc_count": 0, 
     "buckets": [ 
      { 
       "key": 1200, 
       "doc_count": 1 
      } 
     ] 
     } 
    } 
}` 



    [1]: https://chrome.google.com/webstore/detail/sense-beta/lhjgkmllcaadmopgmanpapmpjgmfcfig?hl=en 
+0

Спасибо за ответ, я знаю, как добавить данные, но проблема в том, что я хочу, чтобы хранить не анализируемые данные слишком –

+0

Использование карт следующим образом: '" Name ": { " type ":" string ", " store ": true, " index_analyzer ":" index_analyzer ", " search_analyzer ":" search_an alyzer», "полей": { "оригинала": { "типа": "строка", "Индекс": "not_analyzed" } } }' ' вы можете искать 'не проанализированных поле' например «Name.original» – Bala

+0

Я не знаю имен полей –

0

найдено решение

curl -X PUT /index 

{ 
"mappings": { 
    "_default_": { 
     "dynamic_templates": [ 
      { 
       "default": { 
        "match": "*", 
        "match_mapping_type": "string", 
        "mapping": { 
         "type": "string", 
         "index": "not_analyzed" 
        } 
       } 
      } 
     ] 
    } 
} 

}