【问题标题】:Elastic-search search with both should and must具有应该和必须的弹性搜索搜索
【发布时间】:2019-06-20 17:41:09
【问题描述】:

我需要使用 must 和 should 搜索产品。 示例查询:黑色男士牛仔裤。 我有字段性别,所以性别=男人是必须的。剩余的查询转到标题和描述等其他字段。有人可以帮我形成一个查询吗?

query: {
  bool: {
    should: [{
        match: {
          title: {
            query: search_term,
            boost: 5,
            analyzer: 'my_analyzer',
            minimum_should_match: '80%',
          }
        }
      },
      {
        match: {
          queries: {
            query: search_term,
            boost: 10,
            minimum_should_match: '90%',
          }
        }
      },
      {
        match: {
          gender: {
            query: gender,
            boost: 8,
            minimum_should_match: '100%',
          }
        }
      },
      {
        match: {
          color: {
            query: color,
            boost: 5,
            minimum_should_match: '100%',
          }
        }
      }
    ]
  }
}

我已经尝试过了,但没有工作。谁能让我更好地进行搜索。

【问题讨论】:

  • 无论您尝试过什么,请向您提出问题。

标签: node.js elasticsearch search full-text-search


【解决方案1】:

这应该满足您的要求:

GET <indexname>/_search
{

  "query": {
    "bool": {
      "must": 
        {
          "match_phrase": {
            "geneder": "men"
          }
        },
      "should": [
        {
          "match": {
            "title": "diesel"
          }
        },
        {
          "match": {
            "description": "Strechable denim jeans for men"
          }
        }],
        "minimum_should_match": 1
    }
  }
}

【讨论】:

    猜你喜欢
    • 2021-10-27
    • 1970-01-01
    • 2012-02-12
    • 2017-09-10
    • 2016-03-28
    • 2021-02-04
    • 1970-01-01
    • 2018-10-26
    • 2021-08-25
    相关资源
    最近更新 更多