Query DSL builders
Searchkit
ships with many query builders to be used internally and externally to searchkit. This is to remove boilerplate and errors when constructing complicated elastic queries.
Term based queries
TermQuery(field, value)
import {TermQuery} from "searchkit"
TermQuery("color", "red")
TermsQuery(field, values)
import {TermsQuery} from "searchkit"
TermsQuery("color", ["red", "orange"])
RangeQuery(field, from to)
import {RangeQuery} from "searchkit"
RangeQuery("rating", 1, 11])
/* {
range:{
rating:{ gte:1, lt:11}
}
}
}*/
Compound queries
BoolMust(filter)
import {BoolMust, TermQuery} from "searchkit"
//array
BoolMust([
Term("color", "orange"),
Term("brand", "boss")
])
//single filter
BoolMust(Term("color", "red"))
BoolMustNot(filter)
See BoolMust
BoolShould(filter)
See BoolMust
FilteredQuery(filteredOb)
import {FilteredQuery, MatchQuery, TermQuery} from "searchkit"
Filtered({
query:MatchQuery("title", "Star Wars"),
filter:TermQuery("genre", "Action")
})
Full text based queries
MatchQuery(field, query, options)
import {MatchQuery} from "searchkit"
MatchQuery("color", "red yellow", {
operator:'AND'
//...other match query options
})
MatchPhrasePrefix(query, str)
import {MatchPhrasePrefix} from "searchkit"
MatchPhrasePrefix('title', 'spide')
//with optional boost
MatchPhrasePrefix('title^10', 'spide')
MultiMatchQuery(query, options)
import {MultiMatchQuery} from "searchkit"
MultiMatchQuery("red", {
fields:["color", "song_title"],
operator:"OR"
//.. other multi match query options
})
SimpleQueryString(query, options)
import {SimpleQueryString} from "searchkit"
SimpleQueryString("red AND blue", {
fields:["color", "song_title"],
operator:"OR"
//.. other simple query options
})