首页 > 解决方案 > 带有 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"}

标签: elasticsearchsearch

解决方案


我已经找到了上述问题的解决方案。

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字段作为优先级。


推荐阅读