哪个数据库/云服务提供了简单的方法来实现倒排搜索索引?
我有表的 id 及其列的 id,并且需要查找具有以下一组列的所有表。我需要定期添加/删除表。
Elasticsearch 实现示例:
索引创建:
文档摄取:
from elasticsearch import Elasticsearch
# Initialize Elasticsearch client
es = Elasticsearch()
# Create an index with a mapping
index_name = 'tables'
mapping = {
"mappings": {
"properties": {
"table_id": {"type": "keyword"},
"columns": {"type": "integer"} # Ensure this matches the type of your data
}
}
}
es.indices.create(index=index_name, body=mapping)
# Add a document
doc = {
"table_id": "table_1",
"columns": [1, 2, 3]
}
es.index(index=index_name, id=1, body=doc)
# Search for tables containing specific columns
search_body = {
"query": {
"bool": {
"must": [
{"term": {"columns": 1}},
{"term": {"columns": 2}}
]
}
}
}
response = es.search(index=index_name, body=search_body)
print(response)
这种方法应该允许您有效地按列搜索表并管理表数据的定期更新。