[英]Why is my ElasticSeach query returning zero document?
I am trying to query an AWS ElasticSearch Domain from a Lambda worker.我正在尝试从 Lambda 工作人员查询 AWS ElasticSearch 域。
To do so, I am using http-aws-es and the main javascript client for Elastic Search.为此,我使用http-aws-es和主要的 javascript 客户端进行弹性搜索。
I query documents with the following relevant fields:我查询具有以下相关字段的文档:
ref
field - Stringref
字段 - 字符串status
field - String ENUM ( REMOVED
, BLOCKED
, PUBLISHED
, PENDING
, VERIFIED
) status
字段 - 字符串枚举( REMOVED
、 BLOCKED
、 PUBLISHED
、 PENDING
、 VERIFIED
)field
field - String Arrayfield
字段 - 字符串数组thematics
field - String Arraythematics
领域——字符串数组What I want to achieve is:我想要实现的是:
PUBLISHED
or VERIFIED
or where the ref
field is setPUBLISHED
或VERIFIED
或设置了ref
字段的文档keywwords
argument (string array) relatively to values in field
and thematics
keywwords
参数(字符串数组)相对于field
和thematics
中的值的最佳匹配PUBLISHED
status firstPUBLISHED
状态的文档 I found the more_like_this
operator, and gave it a try.我找到了
more_like_this
运算符,并试了一下。 I build step by step my query and the actual version, at least, doesn't return an error, but no documents are returned.我一步一步地构建我的查询,至少实际版本不会返回错误,但不会返回任何文档。 It still misses the
ref
filter + #3 and #4 from above.它仍然错过了上面的
ref
过滤器 + #3 和 #4。 Here is the query:这是查询:
const client = new elasticsearch.Client({
host: ELASTICSEARCH_DOMAIN,
connectionClass: httpAwsEs,
amazonES: {
region: AWS_REGION,
credentials: new AWS.EnvironmentCredentials('AWS')
}
})
let keywords = event.arguments.keywords
let rst = await client.search({
body: {
'query': {
'bool': {
'filter': {
'bool': {
'must_not': [
{
'term': {
'status': 'REMOVED'
}
},
{
'term': {
'status': 'PENDING'
}
},
{
'term': {
'status': 'BLOCKED'
}
}
]
}
},
'must': {
'more_like_this': {
'fields': ['field', 'thematics'],
'like': keywords,
'min_term_freq': 1,
'max_query_terms': 2
},
'should': [
{
'term': {
'status': 'PUBLISHED'
}
}
]
}
}
}
}
})
console.log(rst)
return rst
I have to upload my lambda code to debug this and it complicates debugging a lot.我必须上传我的 lambda 代码来调试它,它使调试变得很复杂。 Since I never made ES queries before, I wanted to have at least some hints as to how to proceed with this or know if I am misusing the ES query syntax.
由于我以前从未进行过 ES 查询,因此我想至少获得一些关于如何进行此操作的提示,或者知道我是否在滥用 ES 查询语法。
EDIT:编辑:
As requested, here is my index mapping (with JS type):根据要求,这是我的索引映射(带有 JS 类型):
Taken from AWS elastic search management console (index tabs > mappings)取自 AWS 弹性搜索管理控制台(索引选项卡 > 映射)
There are one or two issues in your query ( should
inside must
and must_not
inside filter
).您的查询中存在一两个问题(
should
在must
和must_not
在filter
内)。 Try the simplified query below instead:请尝试下面的简化查询:
{
'query': {
'bool': {
'must_not': [
{
'term': {
'status.keyword': 'REMOVED'
}
},
{
'term': {
'status.keyword': 'PENDING'
}
},
{
'term': {
'status.keyword': 'BLOCKED'
}
}
],
'must': [
{
'more_like_this': {
'fields': [
'field',
'thematics'
],
'like': keywords,
'min_term_freq': 1,
'max_query_terms': 2
}
}
],
'should': [
{
'term': {
'status.keyword': 'PUBLISHED'
}
}
]
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.