【问题标题】:Override search requirement in Elasticsearch覆盖 Elasticsearch 中的搜索要求
【发布时间】:2013-11-08 01:46:16
【问题描述】:

我们在索引中搜索以下字段:

  • individual_name (字符串)
  • 组织名称​​(字符串)
  • 个人资料(字符串)
  • 位置(字符串)
  • 全国 (布尔值)

如果用户在“汉密尔顿”中搜索“验光师”,并且我们索引中的验光师将自己列为“全国性”(但不是专门在汉密尔顿),则期望的行为是验光师会出现在汉密尔顿结果中- 有效地忽略了位置要求。

我们目前正在运行multi_match 查询,下面是一个示例。

{
    "query": {
        "filtered" : {
            "query" : {
                "multi_match": {
                    "query": "optometrist",
                    "zero_terms_query": "all",
                    "operator": "and",
                    "fields": [
                        "individual_name^1.2",
                        "organisation_name^1.5",
                        "profile",
                        "accreditations"
                    ]
                }
            },
            "filter": {
                "and": [{
                    "term": {
                        "locations" : "hamilton"
                    }
                }],
            }
        }
    }
}

如何修改它以便为该查询返回带有"nationwide": "yes" 的文档,而不管位置如何?

我在and 下尝试了or 查询,但当然忽略了multi_match

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    我认为这会给你想要的结果:

    {
        "query": {
            "filtered" : {
                "query" : {
                    "multi_match": {
                        "query": "optometrist",
                        "zero_terms_query": "all",
                        "operator": "and",
                        "fields": [
                            "individual_name^1.2",
                            "organisation_name^1.5",
                            "profile",
                            "accreditations"
                        ]
                    }
                },
                "filter": {
                    "or": [
                            {"term": {"locations" : "hamilton"}},
                            {'term' : {'nationwide' : 'yes'}}        
                     ],
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-13
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多