我试图破解elasticsearch查询语言,到目前为止我没有做得很好。ElasticSearch查询标签
我对我的文档有下面的映射。
{
"mappings": {
"jsondoc": {
"properties": {
"header" : {
"type" : "nested",
"properties" : {
"plainText" : { "type" : "string" },
"title" : { "type" : "string" },
"year" : { "type" : "string" },
"pages" : { "type" : "string" }
}
},
"sentences": {
"type": "nested",
"properties": {
"id": { "type": "integer" },
"text": { "type": "string" },
"tokens": { "type": "nested" },
"rhetoricalClass": { "type": "string" },
"babelSynsetsOcc": {
"type": "nested",
"properties" : {
"id" : { "type" : "integer" },
"text" : { "type" : "string" },
"synsetID" : { "type" : "string" }
}
}
}
}
}
}
}
}
它主要类似于引用pdf文档的JSON文件。
我一直在尝试使用聚合进行查询,并且到目前为止效果很好。我已经到了(汇总)rhetoricalClass
的分组点,得到的总重复次数为babelSynsetsOcc.synsetID
。甚至相同的查询,甚至通过对整个结果进行分组,header.year
但是,现在,我正在努力过滤包含术语的文档并执行相同的查询。
那么,我该如何进行查询,以便按rhetoricalClass
进行分组,并且只考虑其字段为header.plainText
包含["Computational", "Compositional", "Semantics"]
的那些文档。我的意思是contain
而不是equal
!
如果我做一个粗略的转换为SQL这将是类似的东西,以
SELECT count(sentences.babelSynsetsOcc.synsetID)
FROM jsondoc
WHERE header.plainText like '%Computational%' OR header.plainText like '%Compositional%' OR header.plainText like '%Sematics%'
GROUP BY sentences.rhetoricalClass
是的,你是完全正确的,我应该把更多的精力放在阅读文档,但它是这样一个痛苦的工作,阅读他们的官方文档。我的查询中唯一缺少的是嵌套过滤器,我不知道我怎么可能错过。总之,非常感谢你的贡献 – Mayhem