gpt4 book ai didi

php - Elasticsearch 忽略查询字符串

转载 作者:行者123 更新时间:2023-12-03 00:23:13 24 4
gpt4 key购买 nike

我正在使用 Elasticsearch 在我的数据库中查询作业。下面是我正在使用的查询。

查询应要求以下内容:
-查询匹配文本、名称或描述
-作业必须包含所有给定的类别和分割

但是,我遇到的问题是,当我提出查询并添加分割和类别时。该查询表面上被忽略,并且该请求返回具有给定段和类别的所有作业。

{
"index": "jobs",
"type": "job",
"body": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"match": {
"categories": "23"
}
},
{
"match": {
"segments": "10"
}
}
],
"should": [
{
"match": {
"name": "php"
}
},
{
"match": {
"text": "php"
}
},
{
"match": {
"description": "php"
}
}
]
}
},
"filter": {
"nested": {
"path": "networks",
"filter": {
"bool": {
"must": [
{
"term": {
"networks.id": 1
}
},
{
"term": {
"networks.status.raw": "PRODUCTION"
}
},
{
"range": {
"networks.start": {
"lte": "now"
}
}
},
{
"range": {
"networks.end": {
"gte": "now"
}
}
}
]
}
}
}
}
}
},
"aggs": {
"categories": {
"terms": {
"field": "categories"
}
},
"segments": {
"terms": {
"field": "segments"
}
}
}
}
}

作为旁注,我使用的是 laravel 和 elasticsearch 的 php 实现,上面是查询数组的 json_encoded 表示。 (类型可以杂耍)

最佳答案

好的,我自己想通了:

用 must 子句中的 multi_match 替换 bool 查询中的 should 参数将解决我的问题。

{
"index": "jobs",
"type": "job",
"body": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "php",
"fields": [
"name",
"text",
"description"
]
}
},
{
"match": {
"segments": "10"
}
}
]
}
},

结果很明显,因为它在文档中注明:

The clause (query) should appear in the matching document. In a boolean query with no must clauses, one or more should clauses must match a document. The minimum number of should clauses to match can be set using the minimum_should_match parameter.



http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#query-dsl-bool-query

关于php - Elasticsearch 忽略查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28830680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com