Our Online Code Hosting solution (formerly MunicodeNEXT) uses ElasticSearch 5.5 to perform searches across code, ordinance, and document content types. Most users can simply enter one or more keywords into the search box to find what they're looking for. However, power users may want to be a bit more specific with their searches.
This article will outline the modifiers and operators supported by ElasticSearch that can be used for more advanced, specific searches.
Article Navigation
Search Defaults
Searches with no operators will default to the following settings:
-
Keywords: Our search engine returns documents with a high frequency of matched keywords. If a search term only includes two keywords (
barking dog
), then only documents containing both keywords are returned. If a search term includes more than two keywords, only documents matching 75% of the keywords are returned. -
Stemming: All search terms will be stemmed by default, except for those included in quotation marks. For example, searching for
park
will also return results forparks
,parking
, andparked
. -
Synonyms: We leverage a global synonym list and return documents with matched synonyms for all searches. For example, searching for
chicken
will also return documents containing the termfowl
, and vice versa.
Exact Phrase Searching
Adding quotation marks (" ") around a phrase forces the application to return results containing all of the terms present in the phrase. Stemming is turned off when performing an exact phrase query.
Example: "sign dimensions"
Wildcard Searches
Wildcard searches, or searches for alternative forms of a word, can be run on individual terms using a question mark (?) to replace a single character and an asterisk (*) to replace zero or more characters.
Example: qu?ck bro*
Proximity Searches
Proximity searches allow you to specify the distance between terms within the text. The tilde (~) symbol is used along with a number to designate how far apart words should be from each other. The example search below will find documents that include the words dogs and cats with 10 or fewer words between.
Example: "dogs cats"~10
Boosting a Term
You can boost the relevance of a term in a matching document by using the carat (^) symbol and a number.
Example: dogs^4 cats
Boolean Operators
By default, all search terms are optional as long as one term matches. To provide more control, you may use Boolean operators +
and -
.
A search for quick brown +fox -news
states that:
- fox must be present (+)
- news must not be present (-)
- quick and brown are optional (their presence increases relevance)
The familiar operators AND
, OR
, and NOT
(also written &&
, ||
and !
) are also supported. However, the effects of these operators can be more complicated than is obvious at first glance. NOT
takes precedence over AND
, which takes precedence over OR
. While the +
and -
only affect the term to the right of the operator, AND
and OR
can affect the terms to the left and right.
Rewriting the above query using AND
, OR
, and NOT
demonstrates the complexity:
quick OR brown AND fox AND NOT news
This is incorrect because brown is now a required term.
(quick OR brown) AND fox AND NOT news
This is incorrect because at least one of quick or brown is now required and the search for those terms would be scored differently from the original query.
((quick AND fox) OR (brown AND fox) OR fox) AND NOT news
This form now replicates the logic from the original query correctly, but the relevance scoring bears little resemblance to the original.
Grouping
Multiple terms or clauses can be grouped with parentheses, to form sub-queries.
Example: (quick OR brown) AND fox
Comments
Let us know what was helpful or not helpful about the article.0 comments
Please sign in to leave a comment.