gpt4 book ai didi

php - Elasticsearch-不同的值,不算数

转载 作者:行者123 更新时间:2023-12-03 00:55:59 26 4
gpt4 key购买 nike

我正在尝试执行与此SQL查询类似的操作:

SELECT * FROM table WHERE fileContent LIKE '%keyword%' AND company_id = '1' GROUP BY email

阅读了 similar to this帖子后,我得到了以下信息:
{
"query": {
"bool": {
"must": [{
"match": {
"fileContent": {
"query": "keyword"
}
}
}],
"filter": [{
"terms": {
"company_id": [1]
}
}]
}
},
"aggs": {
"group_by_email": {
"terms": {
"field": "email",
"size": 1000
}
}
},
"size": 0
}

字段映射为:
{
"cvs" : {
"mappings" : {
"application" : {
"_meta" : {
"model" : "Acme\\AppBundle\\Entity\\Application"
},
"dynamic_date_formats" : [ ],
"properties" : {
"email" : {
"type" : "keyword"
},
"fileContent" : {
"type" : "text"
},
"company_id" : {
"type" : "text"
}
}
}
}
}
}

...是从Symfony config.yml生成的:
fos_elastica:
clients:
default:
host: "%elastica.host%"
port: "%elastica.port%"
indexes:
cvs:
client: default
types:
application:
properties:
fileContent: ~
email:
index: not_analyzed
company_id: ~
persistence:
driver: orm
model: Acme\AppBundle\Entity\Application
provider: ~
finder: ~

过滤器工作正常,但是我发现 hits:hits不返回任何项目(如果删除 size:0,则不返回所有与搜索匹配的结果),并且 aggregations:group_by_email:buckets拥有组的数量,但没有记录本身。分组的记录不会返回,而是我需要的。

如果这是您的首选样式,我也尝试使用查询生成器对FOSElasticBundle进行尝试(此方法有效,但没有分组/聚合):
$boolQuery = new \Elastica\Query\BoolQuery();

$filterKeywords = new \Elastica\Query\Match();
$filterKeywords->setFieldQuery('fileContent', 'keyword');
$boolQuery->addMust($filterKeywords);

$filterUser = new \Elastica\Query\Terms();
$filterUser->setTerms('company_id', array('1'));
$boolQuery->addFilter($filterUser);

$finder = $this->get('fos_elastica.finder.cvs.application');

谢谢。

最佳答案

为此,您需要在已经使用的top_hits中添加 terms aggregation:

  "aggs": {
"group_by_email": {
"terms": {
"field": "email",
"size": 1000
},
"aggs": {
"sample_docs": {
"top_hits": {
"size": 100
}
}
}
}
}

关于php - Elasticsearch-不同的值,不算数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44034655/

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