Ruby-on-rails 弹性搜索:如何查看索引数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8954785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Elastic Search: how to see the indexed data
提问by Robin
I had a problem with ElasticSearch and Rails, where some data was not indexed properly because of attr_protected. Where does Elastic Search store the indexed data? It would be useful to check if the actual indexed data is wrong.
我在使用 ElasticSearch 和 Rails 时遇到了问题,由于 attr_protected,某些数据没有正确索引。Elastic Search 在哪里存储索引数据?检查实际索引数据是否错误会很有用。
Checking the mapping with Tire.index('models').mappingdoes not help, the field is listed.
检查映射Tire.index('models').mapping没有帮助,该字段已列出。
回答by DrTech
Probably the easiest way to explore your ElasticSearch cluster is to use elasticsearch-head.
探索 ElasticSearch 集群的最简单方法可能是使用 elasticsearch -head。
You can install it by doing:
您可以通过执行以下操作来安装它:
cd elasticsearch/
./bin/plugin -install mobz/elasticsearch-head
Then (assuming ElasticSearch is already running on your local machine), open a browser window to:
然后(假设 ElasticSearch 已经在您的本地机器上运行),打开一个浏览器窗口:
http://localhost:9200/_plugin/head/
http://localhost:9200/_plugin/head/
Alternatively, you can just use curlfrom the command line, eg:
或者,您可以仅curl从命令行使用,例如:
Check the mapping for an index:
检查索引的映射:
curl -XGET 'http://127.0.0.1:9200/my_index/_mapping?pretty=1'
Get some sample docs:
获取一些示例文档:
curl -XGET 'http://127.0.0.1:9200/my_index/_search?pretty=1'
See the actual terms stored in a particular field (ie how that field has been analyzed):
查看存储在特定字段中的实际术语(即该字段是如何被分析的):
curl -XGET 'http://127.0.0.1:9200/my_index/_search?pretty=1' -d '
{
"facets" : {
"my_terms" : {
"terms" : {
"size" : 50,
"field" : "foo"
}
}
}
}
More available here: http://www.elasticsearch.org/guide
更多信息请访问:http: //www.elasticsearch.org/guide
UPDATE : Sense plugin in Marvel
更新:Marvel 中的Sense 插件
By far the easiest way of writing curl-style commands for Elasticsearch is the Sense plugin in Marvel.
到目前为止,curl为 Elasticsearch编写样式命令的最简单方法是Marvel 中的Sense 插件。
It comes with source highlighting, pretty indenting and autocomplete.
它带有源代码突出显示、漂亮的缩进和自动完成功能。
Note: Sense was originally a standalone chrome plugin but is now part of the Marvel project.
回答by Jan Klimo
Absolutely the easiest way to see your indexed data is to view it in your browser. No downloads or installation needed.
查看索引数据的最简单方法绝对是在浏览器中查看。无需下载或安装。
I'm going to assume your elasticsearch host is http://127.0.0.1:9200.
我将假设您的 elasticsearch 主机是http://127.0.0.1:9200.
Step 1
第1步
Navigate to http://127.0.0.1:9200/_cat/indices?vto list your indices. You'll see something like this:
导航到http://127.0.0.1:9200/_cat/indices?v列出您的索引。你会看到这样的东西:
Step 2
第2步
Try accessing the desired index:
http://127.0.0.1:9200/products_development_20160517164519304
尝试访问所需的索引:
http://127.0.0.1:9200/products_development_20160517164519304
The output will look something like this:
输出将如下所示:
Notice the aliases, meaning we can as well access the index at:
http://127.0.0.1:9200/products_development
注意aliases,这意味着我们也可以在以下位置访问索引:
http://127.0.0.1:9200/products_development
Step 3
第 3 步
Navigate to http://127.0.0.1:9200/products_development/_search?prettyto see your data:
导航到http://127.0.0.1:9200/products_development/_search?pretty查看您的数据:
回答by Oleg
回答by notapatch
Aggregation Solution
聚合解决方案
Solving the problem by grouping the data - DrTech's answer used facets in managing this but, will be deprecated according to Elasticsearch 1.0 reference.
通过对数据进行分组来解决问题 - DrTech 的回答使用了 facets 来管理此问题,但根据 Elasticsearch 1.0 参考将被弃用。
Warning
Facets are deprecated and will be removed in a future release. You are encouraged to
migrate to aggregations instead.
Facets are replaced by aggregates - Introduced in an accessible manner in the Elasticsearch Guide - which loads an example into sense..
Facet 被聚合取代——在 Elasticsearch 指南中以一种可访问的方式引入——它加载了一个例子。.
Short Solution
简短的解决方案
The solution is the same except aggregations require aggsinstead of facetsand with a count of 0 which sets limit to max integer- the example code requires the Marvel Plugin
该解决方案是除了聚合相同的需要aggs,而不是facets和一个0计数,其设置限制到最大整数-的示例代码需要奇迹插件
# Basic aggregation
GET /houses/occupier/_search?search_type=count
{
"aggs" : {
"indexed_occupier_names" : { <= Whatever you want this to be
"terms" : {
"field" : "first_name", <= Name of the field you want to aggregate
"size" : 0
}
}
}
}
Full Solution
完整解决方案
Here is the Sense code to test it out - example of a houses index, with an occupier type, and a field first_name:
这是用于测试的 Sense 代码 - 房屋索引示例,具有占用者类型和字段 first_name:
DELETE /houses
# Index example docs
POST /houses/occupier/_bulk
{ "index": {}}
{ "first_name": "john" }
{ "index": {}}
{ "first_name": "john" }
{ "index": {}}
{ "first_name": "mark" }
# Basic aggregation
GET /houses/occupier/_search?search_type=count
{
"aggs" : {
"indexed_occupier_names" : {
"terms" : {
"field" : "first_name",
"size" : 0
}
}
}
}
Response
回复
Response showing the relevant aggregation code. With two keys in the index, John and Mark.
显示相关聚合代码的响应。索引中有两个键,John 和 Mark。
....
"aggregations": {
"indexed_occupier_names": {
"buckets": [
{
"key": "john",
"doc_count": 2 <= 2 documents matching
},
{
"key": "mark",
"doc_count": 1 <= 1 document matching
}
]
}
}
....
回答by brandizzi
A tool that helps me a lot to debug ElasticSearch is ElasticHQ. Basically, it is an HTML file with some JavaScript. No need to install anywhere, let alone in ES itself: just download it, unzip int and open the HTML file with a browser.
一种工具,帮助我很多调试ElasticSearch是ElasticHQ。基本上,它是一个带有一些 JavaScript 的 HTML 文件。无需在任何地方安装,更不用说安装在 ES 本身中:只需下载它,解压 int 并使用浏览器打开 HTML 文件。
Not sure it is the best tool for ES heavy users. Yet, it is really practical to whoever is in a hurry to see the entries.
不确定它是 ES 重度用户的最佳工具。但是,对于急于查看条目的人来说,这确实很实用。
回答by Sudhanshu Gaur
If you are using Google Chrome then you can simply use this extension named as Sense it is also a tool if you use Marvel.
如果你使用的是谷歌浏览器,那么你可以简单地使用这个名为 Sense 的扩展程序,如果你使用 Marvel,它也是一个工具。
https://chrome.google.com/webstore/detail/sense-beta/lhjgkmllcaadmopgmanpapmpjgmfcfig
https://chrome.google.com/webstore/detail/sense-beta/lhjgkmllcaadmopgmanpapmpjgmfcfig
回答by koolhead17
Following @JanKlimo example, on terminal all you have to do is:
按照@JanKlimo 的例子,在终端上你要做的就是:
to see all the Index:
$ curl -XGET 'http://127.0.0.1:9200/_cat/indices?v'
查看所有索引:
$ curl -XGET 'http://127.0.0.1:9200/_cat/indices?v'
to see content of Index products_development_20160517164519304:
$ curl -XGET 'http://127.0.0.1:9200/products_development_20160517164519304/_search?pretty=1'
查看索引的内容products_development_20160517164519304:
$ curl -XGET 'http://127.0.0.1:9200/products_development_20160517164519304/_search?pretty=1'
回答by gd vigneshwar
Kibana is also a good solution. It is a data visualization platform for Elastic.If installed it runs by default on port 5601.
Kibana 也是一个很好的解决方案。Elastic的数据可视化平台,安装后默认运行在5601端口。
Out of the many things it provides. It has "Dev Tools" where we can do your debugging.
在它提供的许多东西中。它有“开发工具”,我们可以在其中进行调试。
For example you can check your available indexes here using the command
例如,您可以使用以下命令在此处检查可用索引
GET /_cat/indices


