【问题标题】:I dont think i fully understand Elastic Search我不认为我完全理解 Elasticsearch
【发布时间】:2016-04-14 18:49:19
【问题描述】:

我正在尝试了解有关 Elastic Search 的一些信息,并想知道是否有人可以帮助我弄清楚。

我的问题是我应该维护多少个索引,以及是否存在过多的风险。假设我想索引图书馆中的书籍并希望能够搜索:

  • 作者
  • 章节名称
  • 书名
  • 出版商

据我所知,ES 是一个文档存储引擎,这意味着存储数据类型而不是规范化的 RDMS 结构。我遇到的复杂情况是我是创建一种数据类型并存储它还是应该创建其他数据类型?

我将如何存储数据以便能够搜索以下组合:

  1. 出版商 X 的所有作者
  2. 以 B 开头且出版商 Y 的书名中的所有章节名称
  3. 作者 X 所著的章节名称为 Y 的书籍的所有出版商

我想知道是否必须为章节创建索引,然后每个章节都有一个包含该书的所有出版商的列表。

我是否过于复杂了?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    从我在您的问题中看到的,您只需要创建一个索引(MySQL 中的数据库模拟),在此索引中您将需要使用内容类型(如 MySQL 中的表)并且每本书都将是数据类型中的文档(类似于 MySQL 中的行)

    你可以像这样添加你的书

    POST library/books/ISBN-10:1449358543
    {
      "type": "Paperback",
      "pages": 724,
      "Publisher": "O'Reilly Media; 1 edition (Feb. 7 2015)",
      "language": "English",
      "tag": "Elasticsearch: The Definitive Guide Paperback – Feb 7 2015\nby Clinton Gormley (Author), Zachary Tong (Author)",
      "desc": "Whether you need full-text search or real-time analytics of structured data—or both—the Elasticsearch distributed search engine is an ideal way to put your data to work. This practical guide not only shows you how to search, analyze, and explore data with Elasticsearch, but also helps you deal with the complexities of human language, geolocation, and relationships.\nIf you’re a newcomer to both search and distributed systems, you’ll quickly learn how to integrate Elasticsearch into your application. More experienced users will pick up lots of advanced techniques. Throughout the book, you’ll follow a problem-based approach to learn why, when, and how to use Elasticsearch features.\nUnderstand how Elasticsearch interprets data in your documents Index and query your data to take advantage of search concepts such as relevance and word proximity Handle human language through the effective use of analyzers and queries Summarize and group data to show overall trends, with aggregations and analytics Use geo-points and geo-shapes—Elasticsearch’s approaches to geolocation Model your data to take advantage of Elasticsearch’s horizontal scalability Learn how to configure and monitor your cluster in production"
    }
    

    您可以按任何字段搜索文档

    POST library/books/_search
    {
      "query": {
        "term": {
          "language": {
            "value": "english"
          }
        }
      }
    }
    

    或任何字段组合

    POST library/books/_search
    {
      "query": {
        "bool": {
          "should": [
            {"term": {
              "language": {
                "value": "english"
              }
            }},
            {"term": {
              "type": {
                "value": "paperback"
              }
            }}
          ]
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-04-29
      • 1970-01-01
      • 2023-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      相关资源
      最近更新 更多