Elasticsearch filter

本文展示了一个使用Elasticsearch进行PHP相关群组搜索的例子,包括如何设置查询条件以匹配特定状态的群组,并对结果进行高亮显示。此外,还提供了一种使用function_score查询来调整结果得分的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

</pre><pre code_snippet_id="1560486" snippet_file_name="blog_20160120_2_5165733" name="code" class="plain">filter
{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "group_audit_status": [
              5,
              99
            ]
          }
        },
        {
          "bool": {
            "should": [
              {
                "multi_match": {
                  "query": "php",
                  "fields": [
                    "ygroup_name"
                  ],
                  "minimum_should_match": 1
                }
              },
              {
                "term": {
                  "group_code": "php"
                }
              },
              {
                "term": {
                  "ngroup_name": "php"
                }
              }
            ]
          }
        }
      ]
    }
  },
  "filter": {
    "bool": {
      "should": [
        {
          "terms": {
            "group_open_status": [
              1,
              100
            ]
          }
        },
        {
          "has_child": {
            "type": "groups_person",
            "query": {
              "term": {
                "person_id": "12819671"
              }
            }
          }
        }
      ]
    }
  },
  "size": 10,
  "from": 0,
  "sort": {
    "_score": {
      "order": "desc"
    }
  },
  "highlight": {
    "fields": {
      "ygroup_name": {}
    },
    "pre_tags": [
      "<font color=red>"
    ],
    "post_tags": [
      "</font>"
    ]
  }
}


function_score  filter
{
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "must": [
            {
              "terms": {
                "group_audit_status": [
                  5,
                  99
                ]
              }
            }
          ]
        }
      },
      "script_score": {
        "script": "1",
        "lang": "groovy"
      },
      "boost_mode": "replace"
    }
  },
  "filter": {
    "bool": {
      "should": [
        {
          "terms": {
            "group_id": [
              103466
            ]
          }
        }
      ]
    }
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值