This project implements a Harvest-Next query evaluator targeting Elasticsearch.
The evaluator acts as a validator for Harvest-Next queries and as an interpreter targeting Elasticsearch 2+. Much like Harvest 2.x, the Harvest-Next query language is json-based and composed of concepts and individual fields. A query will consist of at least one concept term, which is composed of a set of field parameters. A field parameter is an atomic term which contains an identifier for the field (if applicable), an operator, and a value.
A query may also contain one or more branch terms, which allow for boolean logic in concept querying, consist of concept terms and/or other branch terms.
Input query:
{
"type": "query",
"term": {
"type": "branch",
"operator": "and",
"terms": [
{
"type": "concept",
"concept": "audiogram.puretone.f500",
"params": [
{
"id": "response",
"operator": "range",
"value": [20,30]
},
{
"operator": "set",
"value": [1,2,3,4,5]
},
{
"id": "masking_used",
"operator": "-eq",
"value": false
},
{
"id": "no_response",
"operator": "eq",
"value": false
},
{
"id": "vibrotactial_response",
"operator": "eq",
"value": false
}
]
},
{
"type": "branch",
"operator": "or",
"terms": [
{
"type": "concept",
"concept": "audiogram.puretone.pta",
"params": [
{
"id": "ear",
"operator": "eq",
"value": "Left"
},
{
"id": "value",
"operator": "range",
"value": [30,40]
}
]
},
{
"type": "concept",
"concept": "audiogram.puretone.pta",
"params": [
{
"id": "ear",
"operator": "eq",
"value": "Right"
},
{
"id": "value",
"operator": "gt",
"value": 30
}
]
}
]
}
]
}
}
Output Elasticsearch query:
{
"filter": {
"bool": {
"must": [{
"nested": {
"filter": {
"bool": {
"must": [{
"range": {
"audiogram.puretone.f500.response": {
"gte": 20,
"lte": 30
}
}
}, {
"term": {
"_id": [1, 2, 3, 4, 5]
}
}, {
"bool": {
"not": {
"term": {
"audiogram.puretone.f500.masking_used": false
}
}
}
}, {
"term": {
"audiogram.puretone.f500.no_response": false
}
}, {
"term": {
"audiogram.puretone.f500.vibrotactial_response": false
}
}]
}
},
"path": "audiogram.puretone.f500"
}
}, {
"bool": {
"minimum_should_match": 1,
"should": [{
"nested": {
"filter": {
"bool": {
"must": [{
"term": {
"audiogram.puretone.pta.ear": "Left"
}
}, {
"range": {
"audiogram.puretone.pta.value": {
"gte": 30,
"lte": 40
}
}
}]
}
},
"path": "audiogram.puretone.pta"
}
}, {
"nested": {
"filter": {
"bool": {
"must": [{
"term": {
"audiogram.puretone.pta.ear": "Right"
}
}, {
"range": {
"audiogram.puretone.pta.value": {
"gt": 30
}
}
}]
}
},
"path": "audiogram.puretone.pta"
}
}]
}
}]
}
},
"source": "_id"
}
Returns records whose identifiers match a set of values.
{
"operator": "set",
"values": [1,2,3,4,5]
}
Equality term. Accepts numerical, boolean, and string values.
{
"id": "response",
"operator": "eq",
"value": 24
}
Non-equality term. Accepts numerical, boolean, and string values.
{
"id": "response",
"operator": "-eq",
"value": 24
}
Term that checks whether a value for a given field is defined.
{
"id": "race",
"operator": "defined"
}
Term that checks whether a value for a given field is undefined.
{
"id": "race",
"operator": "undefined"
}
Term that, given a list of values, checks if the value of a field matches at least one of the values. Accepts numerical, boolean, and string values.
{
"id": "race",
"operator": "one",
"values": ["white", "asian"]
}
Implements a ES free-text "match" on a text or string field.
{
"id": "note",
"operator": "match",
"value": "cancer oncology"
}
Implements a free-text ES query search of a text or string field.
{
"id": "note",
"operator": "query",
"value": "+(cancer | oncology) neoblastoma"
}
Queries for values greater (exclusive) than the supplied value. Accepts numeric and date values with a "dd/MM/yyyy||yyyy" format.
{
"id": "dob",
"operator": "gt",
"value": "1998"
}
Queries for values greater (inclusive) than the supplied value. Accepts numeric and date values with a "dd/MM/yyyy||yyyy" format.
{
"id": "dob",
"operator": "gte",
"value": "1998"
}
Queries for values less (exclusive) than the supplied value. Accepts numeric and date values with a "dd/MM/yyyy||yyyy" format.
{
"id": "dob",
"operator": "lt",
"value": "1998"
}
Queries for values less (inclusive) than the supplied value. Accepts numeric and date values with a "dd/MM/yyyy||yyyy" format.
{
"id": "dob",
"operator": "lte",
"value": "1998"
}
Queries for values (inclusive) in a given range. Accepts numeric and date values with a "dd/MM/yyyy||yyyy" format.
{
"id": "dob",
"operator": "range",
"value": ["1998", "2003"]
}
Checks whether a given array field is has an empty value.
{
"id": "dob",
"operator": "empty"
}
Checks whether a given array field is has an non-empty value.
{
"id": "dob",
"operator": "nonempty"
}
Checks whether a value is a member of an array field. Accepts numerical, boolean, and string values.
{
"id": "transducers",
"operator": "member",
"value": "ER-3A Inserts"
}
Checks whether an array is a subset of an array field. Accepts numerical, boolean, and string values.
{
"id": "transducers",
"operator": "subset",
"value": ["ER-3A Inserts", "TDH-39 Phones"]
}