简体   繁体   English

我是 ES 新手,在 ES 中有一个多重匹配查询,并希望根据其可用性考虑字段

[英]I am new to ES and have a multi-match query in ES, and want to consider field based on its availability

{
    "multi_match": {
      "query": "TEST",
      "fields": [
        "description.regexkeyword^1.0",
        "logical_name.regexkeyword^1.0",
        "logical_table_name.regexkeyword^1.0",
        "physical_name.regexkeyword^1.0",
        "presentation_name.regexkeyword^1.0",
        "table_name.regexkeyword^1.0"
      ],
      "type": "best_fields",
      "operator": "AND",
      "slop": 0,
      "prefix_length": 0,
      "max_expansions": 50,
      "lenient": false,
      "zero_terms_query": "NONE",
      "boost": 1
    }
  }

There is a field, ie edited_description , if in case edited_description exists in document then consider edited_description.regexkeyword^1.0 else consider description, ie description.regexkeyword^1.0 .有一个字段,即edited_description ,如果edited_description exists于文档中,则考虑edited_description.regexkeyword^1.0 ,否则考虑描述,即description.regexkeyword^1.0

You can't define an if condition in multi_match query.您不能在 multi_match 查询中定义 if 条件。 But what you can do is re-look your problem statement in a different way.但是你能做的是以不同的方式重新审视你的问题陈述。 I can re-look this as, that if in case edited_description and description both exists then the match in edited_description field should be given a higher preference.我可以重新看待这个,如果edited_descriptiondescription都存在,那么edited_description字段中的匹配应该被给予更高的偏好。

This can achieved by setting slightly higher boost value for edited_description field.这可以通过为edited_description字段设置稍高的提升值来实现。

{
  "multi_match": {
    "query": "TEST",
    "fields": [
      "description.regexkeyword^1.0",
      "edited_description.regexkeyword^1.2",
      "logical_name.regexkeyword^1.0",
      "logical_table_name.regexkeyword^1.0",
      "physical_name.regexkeyword^1.0",
      "presentation_name.regexkeyword^1.0",
      "table_name.regexkeyword^1.0"
    ],
    "type": "best_fields",
    "operator": "AND",
    "slop": 0,
    "prefix_length": 0,
    "max_expansions": 50,
    "lenient": false,
    "zero_terms_query": "NONE",
    "boost": 1
  }
}

This will result in documents having a match in edited_description to be ranked higher.这将导致在edited_description中匹配的文档排名更高。 You can adjust the boosting value to your needs.您可以根据需要调整提升值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在多字段中使用多重匹配查询不起作用 - Using multi-match query in a multi-field does not work Elasticsearch多匹配查询并匹配单个字段 - Elasticsearch Multi-match query and matching a single field 如何告诉 ElasticSearch 多匹配查询我希望以字符串形式存储的数字字段返回与数字字符串的匹配? - How do I tell an ElasticSearch multi-match query that I want numeric fields, stored as strings, to return matches with numeric strings? 多匹配查询功能得分 - function score with multi-match query ElasticSearch - 多匹配查询返回没有命中数据,即使它在那里 - NodeJS - ElasticSearch - Multi-match Query returning no hits for data even though its there - NodeJS 如何在Elasticsearch多重匹配查询中使用score_mode = sum - How can I use score_mode=sum with Elasticsearch multi-match query Elasticsearch多匹配交叉字段查询与不同的查询分析器 - Elasticsearch multi-match cross fields query with different query analyzers Elasticsearch 多匹配评分基于匹配亮点的数量 - Elasticsearch multi-match scoring based on the number of matching highlights Elasticsearch 限制多匹配查询的分数影响 - Elasticsearch limit score impact of multi-match query Elasticsearch 多匹配字段不包含查询字符串 - Elasticsearch multi-match fields doesn't include query string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM