json - 在弹性搜索中存储布尔值:优化?
问题描述
我有 json 文档,其中包含以下条目:
......
{
"Fieldname" : "booked",
"Fieldvalue" : "yes"
}
...
在 json 文档中,有很多这样的字段,其中布尔值是使用 Fieldname 和 Fieldvalue 间接提及的:本质上它表示booked=true。在将 json 存储到 elasticsearch 之前转换它会更有效吗?即用以下内容替换上述内容:
{
"booked" : true
}
? 搜索用例是我想在添加另一个json之前弄清楚系统中是否已经存在类似的json。
解决方案
是的,后一种是存储和搜索目的的更清洁的方式。假设您想从索引中获取所有预订的属性,那么您可以轻松地这样做,而不是使用额外的Fieldname和Fieldvalue
GET /properties/_search
{
"size": 10,
"query": {
"bool": {
"must": [
{
"match": {
"country_code.keyword": "US"
}
},
{
"match": {
"booked": true
}
},
{
"range": {
"usd_price": {
"gte": 50,
"lte": 100000
}
}
}
]
}
},
"sort": [
{
"ranking": {
"order": "desc"
}
}
],
"_source": [
"property_id",
"property_name",
"country",
"country_code",
"state",
"state_abbr",
"city"
]
}
推荐阅读
- xml - 线程“主”javax.persistence.PersistenceException 中的异常:持久性.xml 无效。解析 XML 时出错(第 1 行:第 -1 列)
- c# - 如何在 C# 中返回泛型类对象?
- python - 根据特定的键和值从列表中删除重复的字典
- java - 如何使用正确的语法在 Oracle DB 中插入值
- javascript - 使用 onClick在 React中呈现的最简单方法?
- jquery - 为什么 Jquery 加载方法不起作用 laravel
- jupyter-notebook - Jupyter Notebook 单元停止工作
- python - np.r_ 不适用于 2 个范围或多个切片
- android - 键入'_InternalLinkedHashMap
' 不是类型转换中类型 'Session' 的子类型 - c - 当 stdin 和 stdout 都连接到命名管道时,是否可以防止应用程序挂起?