View a markdown version of this page

Key differences - AWS Prescriptive Guidance

Key differences

The following table lists the key differences between Solr and OpenSearch search features.

Feature Solr OpenSearch

Full-text search

Query parsers: Standard, DisMax, Extended DisMax (eDisMax), Simple

Match, multi-match, query string, match phrase, and so on

Faceting

facet, facet.pivot, json.facet parameters

Metric, bucket, and pipeline aggregations

Filtering

Filter query (fq) parameter

Filter context

Boosting

DisMax, eDisMax query

Boosting, disjunction, function score

Highlighting

unified, original, fastVector parameters

unified, fvh, plain, semantic highlighters

Suggestions

Suggester component

Autocomplete

Geospatial

Spatial search

Geographic and XY queries

The following table lists frequently used query types in Solr and how to rewrite them in OpenSearch.

Query type Solr OpenSearch

Basic Boolean query

Solr:

# Simple field query q=title:java # Multiple field queries q=title:java AND author:smith q=title:java OR author:python

 

 // Simple field query { "query": { "term": { "title": "java" } } } // Multiple field queries - AND { "query": { "bool": { "must": [ {"term": {"title": "java"}}, {"term": {"author": "smith"}} ] } } } // Multiple field queries - OR { "query": { "bool": { "should": [ {"term": {"title": "java"}}, {"term": {"author": "python"}} ] } } }

Full-text search queries with boost

 

# Solr DisMax q=java programming&defType=dismax&qf=title^2 content author # Solr eDisMax with phrase boost q=java programming&defType=edismax&qf=title^3 content^1&pf=title^10&mm=75%
// Basic multi-match { "query": { "multi_match": { "query": "java programming", "fields": ["title^2", "content", "author"] } } } // Advanced multi-match with phrase boost { "query": { "bool": { "must": [ { "multi_match": { "query": "java programming", "fields": ["title^3", "content"], "minimum_should_match": "75%" } } ], "should": [ { "match_phrase": { "title": { "query": "java programming", "boost": 10 } } } ] } } }

Range queries

 

# Numeric range q=price:[10 TO 50] # Date range q=publishDate:[2020-01-01T00:00:00Z TO 2023-12-31T23:59:59Z] # Open-ended range q=price:[10 TO *] q=price:[* TO 50]
// Numeric range { "query": { "range": { "price": { "gte": 10, "lte": 50 } } } } // Date range { "query": { "range": { "publishDate": { "gte": "2020-01-01T00:00:00Z", "lte": "2023-12-31T23:59:59Z" } } } } // Open-ended range { "query": { "range": { "price": { "gte": 10 } } } }

Wildcard and fuzzy queries

 

# Wildcard queries q=title:jav* q=title:*ava q=title:j?va # Fuzzy queries q=title:java~2 q=title:"java programming"~3
// Wildcard queries { "query": { "wildcard": { "title": "jav*" } } } { "query": { "wildcard": { "title": "*ava" } } } // Fuzzy queries { "query": { "fuzzy": { "title": { "value": "java", "fuzziness": 2 } } } } // Fuzzy phrase query { "query": { "match_phrase": { "title": { "query": "java programming", "slop": 3 } } } }

Filter queries

 

# Filter queries q=java&fq=category:programming&fq=inStock:true&fq=price:[10 TO 50]
{ "query": { "bool": { "must": [ {"match": {"_all": "java"}} ], "filter": [ {"term": {"category": "programming"}}, {"term": {"inStock": true}}, {"range": {"price": {"gte": 10, "lte": 50}}} ] } } }

Phrase and proximity queries

 

# Exact phrase q="java programming" # Proximity search q="java programming"~5 # Phrase with field q=title:"machine learning"~2
// Exact phrase { "query": { "match_phrase": { "_all": "java programming" } } } // Proximity search { "query": { "match_phrase": { "_all": { "query": "java programming", "slop": 5 } } } } // Phrase with specific field { "query": { "match_phrase": { "title": { "query": "machine learning", "slop": 2 } } } }

You can also use span and interval queries for proximity search.

Aggregation

# Basic faceting q=*:*&facet=true&facet.field=category&facet.field=author
// Basic aggregations { "query": {"match_all": {}}, "aggs": { "categories": { "terms": { "field": "category" } }, "authors": { "terms": { "field": "author" } } } }

Nested faceting or aggregation

# nested faceting { "query": "*:*", "facet": { "categories": { "type": "terms", "field": "category", "limit": 10, "facet": { "brands": { "type": "terms", "field": "brand", "limit": 5, "facet": { "avg_price": { "type": "avg", "field": "price" }, "max_price": { "type": "max", "field": "price" } } } } } } }
# OpenSearch nested aggregation { "query": { "match_all": {} }, "size": 0, "aggs": { "categories": { "terms": { "field": "category", "size": 10 }, "aggs": { "brands": { "terms": { "field": "brand", "size": 5 }, "aggs": { "avg_price": { "avg": { "field": "price" } }, "max_price": { "max": { "field": "price" } } } } } } } }

Geospatial queries

 

# Geo distance q={!geofilt pt=37.7752,-122.4232 sfield=location d=10}
// Geo distance { "query": { "geo_distance": { "distance": "10km", "location": { "lat": 37.7752, "lon": -122.4232 } } } }

The following sections discuss some of the Solr search features and their equivalents in OpenSearch in more detail. After migration to OpenSearch, make sure to test all your queries in OpenSearch and compare the results with your Solr-based system. For your search applications, OpenSearch provides both high-level and low-level clients for multiple languages. For more information, see OpenSearch language clients in the OpenSearch documentation.