diff --git a/docs/opensearch/bool.md b/docs/opensearch/query-dsl/bool.md similarity index 99% rename from docs/opensearch/bool.md rename to docs/opensearch/query-dsl/bool.md index 7dae7eda..8f18cebe 100644 --- a/docs/opensearch/bool.md +++ b/docs/opensearch/query-dsl/bool.md @@ -1,7 +1,8 @@ --- layout: default title: Boolean queries -parent: OpenSearch +parent: Query DSL +grand_parent: OpenSearch nav_order: 45 --- diff --git a/docs/opensearch/full-text.md b/docs/opensearch/query-dsl/full-text.md similarity index 97% rename from docs/opensearch/full-text.md rename to docs/opensearch/query-dsl/full-text.md index c1e95f11..0b2e4d5f 100644 --- a/docs/opensearch/full-text.md +++ b/docs/opensearch/query-dsl/full-text.md @@ -1,14 +1,13 @@ --- layout: default title: Full-text queries -parent: OpenSearch +parent: Query DSL +grand_parent: OpenSearch nav_order: 40 --- # Full-text queries -Although you can use HTTP request parameters to perform simple searches, the OpenSearch query domain-specific language (DSL) lets you specify the full range of search options. The query DSL uses the HTTP request body. Queries specified in this way have the added advantage of being more explicit in their intent and easier to tune over time. - This page lists all full-text query types and common options. Given the sheer number of options and subtle behaviors, the best method of ensuring useful search results is to test different queries against representative indices and verify the output. diff --git a/docs/opensearch/query-dsl/index.md b/docs/opensearch/query-dsl/index.md new file mode 100644 index 00000000..92782741 --- /dev/null +++ b/docs/opensearch/query-dsl/index.md @@ -0,0 +1,121 @@ +--- +layout: default +title: Query DSL +nav_order: 27 +parent: OpenSearch +has_children: true +--- + +# Query DSL + +While you can use HTTP request parameters to perform simple searches, you can also use the OpenSearch query domain-specific language (DSL), which provides a wider range of search options. The query DSL uses the HTTP request body, so you can more easily customize your queries to get the exact results that you want. + +For example, the following request performs a simple search to search for a `speaker` field that has a value of `queen`. + +**Sample request** +```json +GET _search?q=speaker:queen +``` + +**Sample response** +``` +{ + "took": 87, + "timed_out": false, + "_shards": { + "total": 68, + "successful": 68, + "skipped": 0, + "failed": 0 + }, + "hits": { + "total": { + "value": 4080, + "relation": "eq" + }, + "max_score": 4.4368687, + "hits": [ + { + "_index": "new_shakespeare", + "_type": "_doc", + "_id": "28559", + "_score": 4.4368687, + "_source": { + "type": "line", + "line_id": 28560, + "play_name": "Cymbeline", + "speech_number": 20, + "line_number": "1.1.81", + "speaker": "QUEEN", + "text_entry": "No, be assured you shall not find me, daughter," + } + } +``` + +With query DSL, however, you can include an HTTP request body to look for results more tailored to your needs. The following example shows how to search for `speaker` and `text_entry` fields that have a value of `QUEEN`. + +**Sample request** +```json +{ + "query": { + "multi_match": { + "query": "QUEEN", + "fields": ["speaker", "text_entry"] + } + } +} +``` + +**Sample Response** +```json +{ + "took": 39, + "timed_out": false, + "_shards": { + "total": 68, + "successful": 68, + "skipped": 0, + "failed": 0 + }, + "hits": { + "total": { + "value": 5837, + "relation": "eq" + }, + "max_score": 7.8623476, + "hits": [ + { + "_index": "new_shakespeare", + "_type": "_doc", + "_id": "100763", + "_score": 7.8623476, + "_source": { + "type": "line", + "line_id": 100764, + "play_name": "Troilus and Cressida", + "speech_number": 43, + "line_number": "3.1.68", + "speaker": "PANDARUS", + "text_entry": "Sweet queen, sweet queen! thats a sweet queen, i faith." + } + }, + { + "_index": "shakespeare", + "_type": "_doc", + "_id": "28559", + "_score": 5.8923807, + "_source": { + "type": "line", + "line_id": 28560, + "play_name": "Cymbeline", + "speech_number": 20, + "line_number": "1.1.81", + "speaker": "QUEEN", + "text_entry": "No, be assured you shall not find me, daughter," + } + } + ] + } +} +``` +The OpenSearch query DSL comes in three varieties: term-level queries, full-text queries, and boolean queries. You can even perform more complicated searches by using different elements from each variety to find whatever data you need. diff --git a/docs/opensearch/term.md b/docs/opensearch/query-dsl/term.md similarity index 99% rename from docs/opensearch/term.md rename to docs/opensearch/query-dsl/term.md index dd8c6df4..457c988c 100644 --- a/docs/opensearch/term.md +++ b/docs/opensearch/query-dsl/term.md @@ -1,7 +1,8 @@ --- layout: default title: Term-level queries -parent: OpenSearch +parent: Query DSL +grand_parent: OpenSearch nav_order: 30 ---