Elastic Search:如何查看索引数据

发布于 2024-12-28 06:29:12 字数 182 浏览 1 评论 0 原文

我在使用 ElasticSearch 和 Rails 时遇到问题,由于 attr_protected,某些数据未正确索引。 Elastic Search 将索引数据存储在哪里?检查实际索引数据是否错误将很有用。

使用 Tire.index('models').mapping 检查映射没有帮助,该字段已列出。

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.

Checking the mapping with Tire.index('models').mapping does not help, the field is listed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

彩扇题诗 2025-01-04 06:29:12

探索 ElasticSearch 集群的最简单方法可能是使用 elasticsearch-head

您可以通过以下方式安装它:

cd elasticsearch/
./bin/plugin install mobz/elasticsearch-head

然后(假设 ElasticSearch 已在您的本地计算机上运行),打开浏览器窗口:

http://localhost:9200/_plugin/head/

或者,您也可以从命令行使用 curl,例如:

检查索引的映射:

curl -XGET 'http://127.0.0.1:9200/my_index/_mapping?pretty=1' 

获取一些示例文档:

curl -XGET 'http://127.0.0.1:9200/my_index/_search?pretty=1' 

查看存储在特定字段中的实际术语(即如何分析该字段):

curl -XGET 'http://127.0.0.1:9200/my_index/_search?pretty=1'  -d '
 {
    "facets" : {
       "my_terms" : {
          "terms" : {
             "size" : 50,
             "field" : "foo"
          }
       }
    }
 }

更多信息请参见此处:<一href="http://www.elasticsearch.org/guide" rel="nofollow noreferrer">http://www.elasticsearch.org/guide

更新:Marvel

到目前为止,为 Elasticsearch 编写 curl 风格命令的最简单方法是 Marvel 中的 Sense 插件

它具有源代码突出显示、漂亮的缩进和自动完成功能。

注意:Sense 最初是一个独立的 Chrome 插件,但现在是 Marvel 项目的一部分

Probably the easiest way to explore your ElasticSearch cluster is to use 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:

http://localhost:9200/_plugin/head/

Alternatively, you can just use curl from the command line, eg:

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

UPDATE : Sense plugin in Marvel

By far the easiest way of writing curl-style commands for Elasticsearch is the Sense plugin in Marvel.

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.

可爱暴击 2025-01-04 06:29:12

查看索引数据的最简单方法绝对是在浏览器中查看。 无需下载或安装。

我假设您的elasticsearch主机是http://127.0.0.1:9200

第 1 步

导航至 http://127.0.0.1:9200/_cat/indices?v 以列出您的索引。您会看到类似这样的内容:

在此处输入图像描述

第 2 步

尝试访问所需的索引:
http://127.0.0.1:9200/products_development_20160517164519304

输出将如下所示:

在此处输入图像描述

注意别名,这意味着我们也可以访问以下位置的索引:
http://127.0.0.1:9200/products_development

第 3 步

导航至 http://127.0.0.1:9200/products_development/_search?pretty 查看您的数据:

在此处输入图像描述

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.

Step 1

Navigate to http://127.0.0.1:9200/_cat/indices?v to list your indices. You'll see something like this:

enter image description here

Step 2

Try accessing the desired index:
http://127.0.0.1:9200/products_development_20160517164519304

The output will look something like this:

enter image description here

Notice the aliases, meaning we can as well access the index at:
http://127.0.0.1:9200/products_development

Step 3

Navigate to http://127.0.0.1:9200/products_development/_search?pretty to see your data:

enter image description here

苄①跕圉湢 2025-01-04 06:29:12

ElasticSearch 数据浏览器

搜索、图表、一键设置......

ElasticSearch data browser

Search, charts, one-click setup....

醉态萌生 2025-01-04 06:29:12

聚合解决方案

通过对数据进行分组来解决问题 - DrTech 的答案使用了方面来管理此问题,但是 将被弃用。

Warning

Facets are deprecated and will be removed in a future release. You are encouraged to
migrate to aggregations instead.

Facets 被聚合替换 - 在 Elasticsearch 指南中以易于理解的方式引入 - 加载了一个示例.

简短的解决方案

该解决方案是相同的,除了聚合需要 aggs 而不是 facets 并使用 计数 0 将限制设置为最大整数 - 示例代码需要 Marvel 插件

# 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
            }
        }
    }
}

完整解决方案

这是用于测试它的 Sense 代码out - 房屋索引示例,具有占用者类型和字段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
            }
        }
    }
}

响应

显示相关聚合代码的响应。索引中有两个键:John 和 Mark。

    ....
    "aggregations": {
      "indexed_occupier_names": {
         "buckets": [
            {
               "key": "john",     
               "doc_count": 2     <= 2 documents matching
            },                        
            {
               "key": "mark",
               "doc_count": 1     <= 1 document matching
            }
         ]
      }
   }
   ....

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.

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..

Short Solution

The solution is the same except aggregations require aggs instead of facets and with a count of 0 which sets limit to max integer - the example code requires the Marvel Plugin

# 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:

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.

    ....
    "aggregations": {
      "indexed_occupier_names": {
         "buckets": [
            {
               "key": "john",     
               "doc_count": 2     <= 2 documents matching
            },                        
            {
               "key": "mark",
               "doc_count": 1     <= 1 document matching
            }
         ]
      }
   }
   ....
一花一树开 2025-01-04 06:29:12

ElasticHQ 是一个对我调试 ElasticSearch 有很大帮助的工具。基本上,它是一个带有一些 JavaScript 的 HTML 文件。无需在任何地方安装,更不用说在 ES 本身中:只需下载它,解压缩 int 并使用浏览器打开 HTML 文件。

不确定它是 ES 重度用户的最佳工具。然而,对于那些急于查看条目的人来说,这确实很实用。

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.

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.

美煞众生 2025-01-04 06:29:12

Kibana 也是一个很好的解决方案。它是 Elastic 的数据可视化平台。如果安装,它默认在端口 5601 上运行。

它提供了许多功能。它有“开发工具”,我们可以在其中进行调试。

例如,您可以使用以下命令在此处检查可用索引

GET /_cat/indices

Kibana is also a good solution. It is a data visualization platform for Elastic.If installed it runs by default on port 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
月棠 2025-01-04 06:29:12

如果你使用 Google Chrome,那么你可以简单地使用这个名为 Sense 的扩展,如果你使用 Marvel,它也是一个工具。

https://chrome.google.com/webstore/detail/sense-beta/lhjgkmllcaadmopgmanpapmpjgmfcfig

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.

https://chrome.google.com/webstore/detail/sense-beta/lhjgkmllcaadmopgmanpapmpjgmfcfig

許願樹丅啲祈禱 2025-01-04 06:29:12

按照@JanKlimo 示例,在终端上您所要做的就是:

查看所有索引:
<代码>
$curl -XGET 'http://127.0.0.1:9200/_cat/indices?v'

查看索引 products_development_20160517164519304 的内容:
<代码>
$curl -XGET 'http://127.0.0.1:9200/products_development_20160517164519304/_search?pretty=1'

Following @JanKlimo example, on terminal all you have to do is:

to see all the Index:

$ 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'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文