Elasticsearch 查詢權重(qbit)

提高字段的權重

multi_match

  • 默認 type 爲 best_fields
GET /_search
{
  "query": {
    "multi_match": {
      "query": "this is a test",
      "fields": ["subject^3", "message"]
    }
  }
}
  • most_fields
GET /_search
{
  "query": {
    "multi_match": {
      "query": "this is a test",
      "type": "most_fields",
      "fields": ["subject^3", "message"]
    }
  }
}
// 等價於
GET /_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": { "subject": { "query": "this is a test", "boost": 3 }}
        },
        {
          "macth": { "message": "this is a test" }
        }
      ]
    }
  }
}

query_string

GET /_search
{
  "query": {
    "query_string": {
      "fields": ["content", "name^5"],
      "query": "this AND that OR thus"
    }
  }
}

simple_query_string

GET /_search
{
  "query": {
    "simple_query_string": {
      "query": """"fried eggs" +(eggplant | potato) -frittata""",
      "fields": ["title^5", "body"],
      "default_operator": "and"
    }
  }
}

提高子句的權重

GET /_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": { "subject": { "query": "this is a test", "boost": 3 }}
        },
        {
          "macth": { "message": "this is a test" }
        }
      ]
    }
  }
}

提高索引的權重

GET /_search
{
    "indices_boost" : [
        { "alias1" : 1.4 },
        { "index*" : 1.3 }
    ]
}
本文出自 qbit snap
相關文章
相關標籤/搜索