索引弹性搜索数据的最佳方法是什么? [英] What is the best way to index data on elasticsearch?

查看:170
本文介绍了索引弹性搜索数据的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4张桌子:


  1. country


  2. city

  3. 地址

  1. country
  2. state
  3. city
  4. address

这些表与ID相关,其中country是最高父母:

These tables are related by ids where country is the top parent:


  • state.countryId

  • city.stateId

  • address.cityId

我想在我的应用程序上集成弹性搜索,并想知道索引这些内容的最佳方法是什么table?

I want to integrate elastic search on my application and want to know what is the best way to index these table?

我应该为每个表创建1个索引,以便每个国家,州,城市和地址都有1个索引吗?

Should i create 1 index for each tables so that i have 1 index for each of country, state, city and address?

或者我应该对表进行非规范化并仅创建1个索引并将所有数据存储为冗余?

Or should i denormalize the tables and create only 1 index and store all the data with redundancy?

推荐答案

ES不怕数据冗余,因此我会明确地反规范化,以便每个文档代表一个这样的地址:

ES is not afraid of redundancy in your data, so I would clearly denormalize so that each document represents one address like this:

{
    "country_id": 1,
    "country_name": "United Stated of America",
    "state_id": 1,
    "state_name": "California"
    "state_code": "CA",
    "city_id": 1,
    "city_name": "San Mateo"
    "zip_code": 94402,
    "address": "400 N El Camino Real"
}

然后,您可以汇总您希望的任何城市,州,国家/地区的数据。

You can then aggregate your data on whatever city, state, country field you wish.

您的里程可能会有所不同,因为它最终取决于您想要查询/汇总数据的方式,但在单个索引中查询此类地址数据要容易得多,而不是达到几个指数。

Your mileage may vary as it ultimately depends on how you want to query/aggregate your data, but it's much easier to query address data like this in a single index instead of hitting several indices.

这篇关于索引弹性搜索数据的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆