I am stuck with generic query for my audit project which consists of over a million+ records. Is there any generic query to generate using my php or jquery code? All I could get is till here where I am using AND
, OR
operators to do same:
{
"filter": {
"AND": {
"filters": [
{
"term": {
"age": "28"
}
}
]
},
"OR": {
"filters": [
{
"term": {
"name": "varsh"
}
}
]
}
}
}
Is there any way so I can use any operator and any field to search for? my UI looks something like this
We have quite the same approach in our application. Users can build their own query with a similar UI (the only difference is we have sub-group, so you can have nested queries).
We use an AST to store users queries, something like :
["a",["o",[{"t":"generic.content","o":"contains","a":"@username"},{"t":"generic.content","o":"contains","a":"#username"]],["a",[{"t":"generic.content","o":"contains","a":"other thing"},{"t":"generic.content","o":"contains","a":"yet another thing"}]],["o",[{"t":"generic.lang","o":"equals_lang","a":"fr"},{"t":"generic.lang","o":"equals_lang","a":"en"}]]]
where ["a", []] is a group with AND operator and ["o", []] a group with OR operator.
Then we use this AST to build an Elasticsearch query using bool query (http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html) dynamically.
In our format negation is handle at the operator level (contains vs !contains), but you could have a group of NOT operator like ["n", []]