diff --git a/_query-dsl/term/terms.md b/_query-dsl/term/terms.md index 089fb16601..5141a0d91c 100644 --- a/_query-dsl/term/terms.md +++ b/_query-dsl/term/terms.md @@ -22,7 +22,6 @@ GET shakespeare/_search } } ``` - {% include copy-curl.html %} A document is returned if it matches any of the terms in the array. @@ -64,7 +63,6 @@ PUT students } } ``` - {% include copy-curl.html %} Next, index three documents that correspond to students: @@ -76,7 +74,6 @@ PUT students/_doc/1 "student_id" : "111" } ``` - {% include copy-curl.html %} ```json @@ -86,7 +83,6 @@ PUT students/_doc/2 "student_id" : "222" } ``` - {% include copy-curl.html %} ```json @@ -96,7 +92,6 @@ PUT students/_doc/3 "student_id" : "333" } ``` - {% include copy-curl.html %} Create a separate index that contains class information, including the class name and an array of student IDs corresponding to the students enrolled in the class: @@ -108,7 +103,6 @@ PUT classes/_doc/101 "enrolled" : ["111" , "222"] } ``` - {% include copy-curl.html %} To search for students enrolled in the `CS101` class, specify the document ID of the document that corresponds to the class, the index of that document, and the path of the field in which the terms are located: @@ -127,7 +121,6 @@ GET students/_search } } ``` - {% include copy-curl.html %} The response contains the documents in the `students` index for every student whose ID matches one of the values in the `enrolled` array: @@ -185,7 +178,6 @@ PUT classes/_doc/102 } } ``` - {% include copy-curl.html %} To search for students enrolled in `CS102`, use the dot path notation to specify the full path to the field in the `path` parameter: @@ -204,7 +196,6 @@ GET students/_search } } ``` - {% include copy-curl.html %} The response contains the matching documents: @@ -262,7 +253,6 @@ Parameter | Data type | Description `boost` | Floating-point | A floating-point value that specifies the weight of this field toward the relevance score. Values above 1.0 increase the field’s relevance. Values between 0.0 and 1.0 decrease the field’s relevance. Default is 1.0. ## Bitmap filtering - **Introduced 2.17** {: .label .label-purple } @@ -282,7 +272,6 @@ PUT /products } } ``` - {% include copy-curl.html %} Next, index three documents that correspond to products: @@ -294,7 +283,6 @@ PUT /products/_doc/1 "product_id" : "111" } ``` - {% include copy-curl.html %} ```json @@ -304,7 +292,6 @@ PUT /products/_doc/2 "product_id" : "222" } ``` - {% include copy-curl.html %} ```json @@ -314,7 +301,6 @@ PUT /products/_doc/3 "product_id" : "333" } ``` - {% include copy-curl.html %} To store customer bitmap filters, you'll create a `customer_filter` [binary field](https://opensearch.org/docs/latest/field-types/supported-field-types/binary/) in the `customers` index. Specify `store` as `true` to store the field: @@ -332,7 +318,6 @@ PUT /customers } } ``` - {% include copy-curl.html %} For each customer, you need to generate a bitmap that represents the product IDs of the products the customer owns. This bitmap effectively encodes the filter criteria for that customer. In this example, you'll create a `terms` filter for a customer whose ID is `customer123` and who owns products `111`, `222`, and `333`. @@ -353,7 +338,6 @@ encoded_bm_str = encoded.decode('utf-8') # Print the encoded bitmap print(f"Encoded Bitmap: {encoded_bm_str}") ``` - {% include copy.html %} Next, index the customer filter into the `customers` index. The document ID for the filter is the same as the ID for the corresponding customer (in this example, `customer123`). The `customer_filter` field contains the bitmap you generated for this customer: @@ -364,7 +348,6 @@ POST customers/_doc/customer123 "customer_filter": "OjAAAAEAAAAAAAIAEAAAAG8A3gBNAQ==" } ``` - {% include copy-curl.html %} Now you can run a `terms` query on the `products` index to look up a specific customer in the `customers` index. Because you're looking up a stored field instead of `_source`, set `store` to `true`. In the `value_type` field, specify the data type of the `terms` input as `bitmap`: @@ -385,7 +368,6 @@ POST /products/_search } } ``` - {% include copy-curl.html %} You can also directly pass the bitmap to the `terms` query. In this example, the `product_id` field contains the customer filter bitmap for the customer whose ID is `customer123`: @@ -401,5 +383,4 @@ POST /products/_search } } ``` - {% include copy-curl.html %}