【问题标题】:Elastic search indexing document弹性搜索索引文档
【发布时间】:2015-12-18 19:49:55
【问题描述】:

我是 Elasticsearch 的新手,并试图了解它的基础知识。

我按照教程安装了 ES。现在,我正在尝试索引此处提​​到的文档 -

https://www.elastic.co/guide/en/elasticsearch/guide/current/_indexing_employee_documents.html

但它会引发错误。

在尝试为文档编制索引之前是否应该先创建索引?

另外,这里使用了哪些命令?那些是 CURL 命令吗?

import requests
r = requests.get('http://localhost:9200/megacorp')

print r.status_code
print r.text
r = requests.get('http://localhost:9200/twitter')

print r.status_code
print r.text
~            

回复

200
{"megacorp":{"aliases":{},"mappings":{"employee":{"properties":{"first_name":{"type":"string"},"last_name":{"type":"string"}}}},"settings":{"index":{"creation_date":"1442881963974","uuid":"5bISz0kqTdyjYgz-Hv548Q","number_of_replicas":"1","number_of_shards":"5","version":{"created":"1070299"}}},"warmers":{}}}
200
{"twitter":{"aliases":{},"mappings":{},"settings":{"index":{"creation_date":"1443018283701","uuid":"3DS6RZPYTWuX0-ah18e-Ww","number_of_replicas":"2","number_of_shards":"3","version":{"created":"1070299"}}},"warmers":{}}}

日志中的错误:

SearchRequest@2e5f4063] lastShard [true]
org.elasticsearch.search.SearchParseException: [megacorp][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"facets":{"0":{"date_histogram":{"key_field":"@timestamp","value_field":"primaries.indexing.index_total","interval":"1y"},"global":true,"facet_filter":{"fquery":{"query":{"filtered":{"query":{"query_string":{"query":"_type:indices_stats"}},"filter":{"bool":{"must":[{"match_all":{}}]}}}}}}}},"size":50,"query":{"filtered":{"query":{"query_string":{"query":"_type:cluster_event OR _type:node_event"}},"filter":{"bool":{"must":[{"match_all":{}}]}}}},"sort":[{"@timestamp":{"order":"desc","ignore_unmapped":true}},{"@timestamp":{"order":"desc","ignore_unmapped":true}}]}]]
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:747)
    at org.elasticsearch.search.SearchService.createContext(SearchService.java:572)
    at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:544)
    at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:306)
    at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:231)
    at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:228)
    at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.search.facet.FacetPhaseExecutionException: Facet [0]: (key) field [@timestamp] not found
    at org.elasticsearch.search.facet.datehistogram.DateHistogramFacetParser.parse(DateHistogramFacetParser.java:172)
    at org.elasticsearch.search.facet.FacetParseElement.parse(FacetParseElement.java:93)
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:731)

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您可以使用 curl 执行这些命令,只需查看所有引号等。例如,这是该教程中删除了一些字段的第一个 PUT 命令:

    curl -X PUT -d "{ \"first_name\": \"John\", \"last_name\": \"Smith\" }" localhost:9200/megacorp/employee/1

    它将创建索引并添加文档。

    如果您转到http://localhost:9200/_plugin/head/,您应该能够看到您的索引。该页面上的浏览器选项卡可让您查看索引中的内容。

    megacorp 索引和员工映射将使用合理的默认值创建,在某些应用程序中,如果您不同意默认值,您可能需要明确定义它们。

    忘了提...如果这不能解决您的问题,请发布您遇到的错误。

    【讨论】:

    • 谢谢..我能够创建索引,但现在的问题是我在 Marvel 仪表板中看不到它们。我已经更新了我的输出。
    【解决方案2】:

    在索引文档之前,您必须先创建索引。要创建索引,您可以发出 POST 请求。创建索引的 curl 请求示例是

    curl -XPOST "http://localhost:9200/test_index"
    

    这将返回一个 true 的确认。 现在你可以索引文档了

    curl -XPOST "http://localhost:9200/test_index/test_type" -d "{\"name\" : \"This is my name\", \"age\" : 25}"
    

    【讨论】:

      猜你喜欢
      • 2015-09-05
      • 1970-01-01
      • 2022-08-12
      • 2018-07-21
      • 2015-06-01
      • 2016-10-08
      • 1970-01-01
      • 2016-10-24
      相关资源
      最近更新 更多