如何创建
我正在尝试创建通过文档字段过滤和文档的WHOLE子对象中的textsearch组合的搜索查询。我陷入了困境,需要帮助,文档链接或任何建议吗?
我需要通过两个关键字列表(必须在文档中{positive_keywords
或应在文档中negative_keywords
)和一些带有简单过滤的数字字段来筛选公司。
我进行了简单的过滤,但是我陷入了在整个子对象中进行全文搜索的困境。
我使用https://github.com/babenkoivan/scout-elasticsearch-driver
文档结构示例-是有关公司的集合:
{
"id": 2838,
"name": "COMPANY NAME GmbH",
"status_id": 0,
"responsible_id": null,
"addresses": [{
"postal_code_start": "65",
"postal_code_length": 5
}],
"latestRevenueStatistics": {
"number_of_employees": 20,
"revenue": "2400000.00"
},
"branches": [{
"id": 1346
}],
"keywords": {
"h1": [
"starten",
"karriere",
"netiquette"
],
"h2": [
"gewappnet",
"zukunft",
"perfekte",
"verbindung",
"teil",
"experts",
"allgeier",
"tochtergesellschaften",
"zertifikate",
"experts"
],
"h3": [
"experten",
"zertifikate
]
...
}
}
子对象keywords
包括以下字段:page_title
,h1
,h2
,h3
,h4
,text
,{{ 1}},of
,meta
等...
我当前对ES的请求(以Scout语法描述的查询,但是在Scout编译后,ES接收到ES的查询如下):
url
例如,要过滤内部关键字,我可以通过向过滤器区域添加query-> bool-> filter-> bool->来触摸keyword.h1,
{
"query": {
"bool": {
"must": {
"query_string": {
"query": "aldi"
}
},
"filter": {
"bool": {
"must": [{
"range": {
"latestRevenueStatistics.revenue": {
"gte": "0",
"lte": "40000000"
}
}
}, {
"range": {
"latestRevenueStatistics.number_of_employees": {
"gte": "0",
"lte": "300"
}
}
}, {
"term": {
"addresses.postal_code_length": 5
}
}]
}
}
}
},
"from": 0,
"size": 10
}
或者这个
"must_not": [{
"term": {
"keywords.h1": "perfekte"
}
}]
如何扩展当前请求以查询关键字子对象内的所有字段?
答案 0 :(得分:0)
您可以将must_not和must条款与您的范围结合使用,如下所示:
POST aggregation_index_2/_search
{
"query": {
"bool": {
"must_not": [
{
"term": {
"your_must_not_field": {
"value": "VALUE"
}
}
},
{
"term": {
"your_must_not_field_2": {
"value": "VALUE"
}
}
}
],
"must": [
{
"range": {
"your_range_field_1": {
"gte": 10,
"lte": 20
}
}
},
{
"range": {
"your_range_field_2": {
"gte": 10,
"lte": 20
}
}
},
{
"term": {
"your_term_field": {
"value": "some_value"
}
}
},
{
"term": {
"your_term_field_2": {
"value": "some_value"
}
}
}
]
}
}
}