elasticsearch - 带有 json 字段的弹性搜索和其他字段的优先级,并在顶部过滤数据
问题描述
我将使用带有一些选定字段的弹性搜索引擎进行搜索。目前,我有以下查询用于搜索选定字段(cna == 城市名称)的“lon”,而不是限制为 10 的优先级。
我想添加 cna (cnm == Country Name) 字段以在顶部过滤“lon”搜索词,然后加载另一个匹配列表。
http://{{ELASTIC_SEARCH_URL}}/rezproduction@@city/city/_search?default_operator=AND&q=cna:lon*&size=10
我在这里添加了我的示例源 json。
{ rid "3"
aid "0"
rnm "North America"
anm ""
cid "12051"
cnid "55"
cncd "US"
sbid ""
sid "50"
lat "46.35564"
lon "-124.05565"
index 0
type "City"
google "N"
cna "Long Beach"
cnm "USA"
sna "Washington"}
解决方案
我已经找到了上述问题的解决方案。
http://{{ELASTIC_SEARCH_URL}}/rezproduction@@city/city/_search?default_operator=AND&q=(cna:lon* AND cnm:{{Country Name which is priority}}) OR (cna:lon*)&size=10
我为优先级列名称添加了带有AND条件的附加查询参数。在这里,我使用了Country Name字段作为优先级。
推荐阅读
- selenium - 无法使用 Windows 10 上的 LWP::UserAgent 从 Perl 访问本地主机上的 selenium 服务器,Strawberry Perl
- python - 如何在熊猫数据框的每一行中找到选定列中的两个最低值?
- python - 将其上传到 PyPI 时出现 Markdown 语法错误
- amazon-web-services - 如何将 pg-promise 与 RDS 代理连接?
- javascript - 如何在 if 语句中创建两个条件
- python - 如何使用 python 访问位于 .jar 文件中的模块?
- networking - 网络地址转换 (NAT) 设备后面可以运行多少设备?
- amazon-web-services - 使用 cloudformation 自动缩放
- python-3.x - 具有 python 多处理的云函数
- python - 特定格式 Python 的当前日期时间