Elasticsearch: how to exclude fields in a query

While querying Elasticsearch, sometimes you might want to exclude certain large fields from the response. To exclude specific fields in an Elasticsearch query, use source filtering: GET /_search { "_source": { "exclude": ["description"] }, "query" : { "term" : { "country" : "france" } } } You can also do source filtering using a GET parameter. curl "localhost:9200/<index>/_doc/1?_source_excludes=description" NOTE: you can also include only specific fields in a search response.

1 min · Kishore Nallan

Elasticsearch: how to include specific fields in a query

While querying Elasticsearch, it’s a good practice to restrict your search results to only the fields you need. To include only specific fields in an Elasticsearch query, use source filtering: GET /_search { "_source": { "include": ["title", "country"] }, "query" : { "term" : { "country" : "france" } } } You can also do source filtering using a GET parameter. curl "localhost:9200/<index>/_doc/1?_source_includes=title,country" NOTE: you can also exclude specific fields in a search response....

1 min · Kishore Nallan

Elasticsearch: must not match text query

In Elasticsearch, to match a given text in a field, you will do it this way: GET /_search { "query":{ "match":{ "country": "France" } } } The must_not bool query Similarly, to identify records whose field value does NOT match a given query string, you can do so using a must_not boolean query: GET /_search { "query": { "bool": { "must_not": [ { "term": { "country": "France" } } ] } } } If this looks a bit verbose, you can also get the same results using a query_string query....

1 min · Kishore Nallan

Elasticsearch: not equal to condition using query string query

Elasticsearch offers a versatile and powerful way to search for records using the query_string query. GET /_search { "query": { "query_string": { "query": "country: France" } } The NOT operator Similarly, to find documents whose field value is NOT equal to a given query string, you can do so using the NOT operator. GET /_search { "query": { "query_string": { "query": "NOT (country: France)" } } # or GET /_search { "query": { "query_string": { "query": "!...

1 min · Kishore Nallan

Full Text search in MongoDB (with examples)

This post will show you how to do a full-text search using text indexes on a MongoDB collection. I will use be using Nodejs code snippets in the examples. For other client libraries and mongo shell commands please refer to the documentation. Creating a Text Index To create a text index use createIndex() function, await client .db("<database-name>") .collection("<books>") .createIndex({ name: "text", description: "text", }); The above code creates an index from the name and description fields....

3 min · Harisaran

Full text search in MySQL (with examples)

While MySQL is not a fully featured text search engine, it has enough tricks up its sleeve to be useful for implementing basic search features in your application. Let’s take a quick walk through. First, let’s open up the mysql prompt and create a new Database and call it restaurant. Now, we can proceed to create a TABLE to store our records. We must be careful here as we need to clearly specify the fields that need to be ‘Full-text indexed'....

7 min · Sabesh Bharathi

Fuzzy Search with Javascript

Fuzzy Search refers to the process of approximately searching for a given search query. It may also be called as a “typo tolerant search”. Let’s say you want to search a recipe database for szechuan noodles but you can’t remember how exactly szechuan is spelt. So you can type in a query that you think is the closest to the actual query: schezwan noodles and it will give you results for similar words and you will end up finding the intended recipe for Szechuan Noodles....

6 min · Sabesh Bharathi

Fuzzy string matching in Python (with examples)

In information systems, it is common to have the same entity being represented by slightly varying strings. Consider the following: Joe Biden Joseph Biden Joseph R Biden All three strings refer to the same person, but in slightly different ways. Fuzzy search is the process of finding strings that approximately match a given string. Let’s explore how we can utilize various fuzzy string matching algorithms in Python to compute similarity between pairs of strings....

4 min · Kishore Nallan

What is fuzzy search?

Fuzzy search is the process of finding strings that approximately match a given string. A fuzzy matching search algorithm will be able to find relevant strings even if your original string contains typo errors and misspellings. Ever seen Google correcting you like this? That’s Google using fuzzy search to match your misspelled query to the word with the correct spelling. Fuzzy search is effective, when it can reliably detect the intent behind a given search term....

2 min · Kishore Nallan