_search/*/_search
Smartsite 8.0 - ...
Purpose
Accepts a search specification and performs a search.
Search
Performs a search where a number of search decisions are built-in.
POST _search/<index names>/_search { "query": { "search_query": { "multi_match": { "query": "search text", "fields": [ { "name": "doc_title", "type": "full-text", "weight": 2 }, { "name": "doc_body", "type": "full-text" }, { "name": "doc_description", "type": "full-text" }, { "name": "doc_authors", "type": "value-of-field" } ], "use_and": false }, "terms": { "extra_tags": { "use_and": true, "terms": [ "wheather", "wind" ] } }, "range": { "doc_created": [ { "gte": "now/y" } ] } } }, "from": 0, "size": 10, "sort": [ { "doc_created": { "order": "desc" } }, { "_score": { "order": "desc" } } ], "_source": { "excludes": [ "doc_body", "nested.doc_body" ] }, "aggregations": { "TagsAggregation": { "terms": { "field": "extra_tags", "size": 20 }, "friendly_name": "Tags" }, "DateRangesAggregation": { "date_range": { "field": "doc_created", "ranges": [ { "key": "Older than 5 calendar years", "to": "now-5y/y" }, { "key": "Previous 5 calendar years", "from": "now-5y/y", "to": "now/y" }, { "key": "This year", "from": "now/y" } ] }, "friendly_name": "Creation date ranges" } } }
Result (shortened):
{ "took": "13", "hits": { "total": { "value": 1 }, "hits": [ { "_id": "43601", "_score": 14.073436, "_source": { "doc_title": "...", "doc_authors": [ "..." ], "doc_description": "...", "doc_body": "...", "doc_fileformat": "Html", "doc_identifier": "tcm:26-328395-64", "doc_language": "Dutch", "doc_url": "...", "doc_created": "2023-08-22T12:14:50", "doc_modified": "2023-08-23T14:10:12", "extra_tags": [ "..." ], "system_number": 43601, "system_guid": "697b5b99-345b-4441-9ff5-37db1071806e", "system_location": "...", "system_provider_code": "WEBCRAWLERPROVIDER", "system_document_size": 15084, "system_usergroups": [ "EVERYONE" ] } } ] }, "aggregations": { "TagsAggregation": { "buckets": [ { "key": "...", "doc_count": 1 }, { "key": "...", "doc_count": 1 } ] }, "DateRangesAggregation": { "buckets": [ { "key": "Older than 5 calendar years", "doc_count": 0 }, { "key": "Previous 5 calendar years", "doc_count": 0 }, { "key": "This year", "doc_count": 1 } ] } } }
Search notes:
- "search_query". Requests to use the search query support that takes a number of search decisions.
- "multi_match". Main query, searching multiple fields.
- "multi_match", "query": "search text". Text typed by the user.
- "multi_match", "fields". Lists the fields to be searched.
- "name": "doc_title". Field name.
- "type": "full-text". Requests full text seach, with stemming and breaking. "value-of-field" would request to match the whole field, case insensitive. This could be used for categories. "values-within-field" would request appearance of the search term somewhere in the field, without applying stemming and breaking.
- "weight": 2. Applies a weight to the field. Defaults to 1.
Fields can be omitted in order to apply a default:
doc_title | full-text | 1 |
doc_body | full-text | 1 |
doc_description | full-text | 1 |
doc_authors | value-of-field | 1 |
doc_keywords | full-text | 1 |
- "multi_match", "use_and": false. Has an effect if the query text contains multiple search terms. False by default, resulting in a default Elastic Search search and resulting in potentially many hits due to OR-like handing of the search terms. Many hits is not an issue: hits are by default ordered on descending score. True to request making modifications to the query for AND-like behaviour. This may for example reduce the number of hits by a factor 10.
- "terms". Optional filter query. It requests to filter the results on values wheather or wind, in field extra_tags.
- "terms", "extra_tags", "use_and": true. Requests an AND for the terms. False requests an OR.
- "range". Optional filter query. It requests to filter the results on date ranges, in field doc_created. For a page on date range aggregation and filtering refer to Date range search.
- "use_and": false. Has an effect if the query text contains multiple search terms. False by default, resulting in a default Elastic Search search and resulting in potentially many hits due to OR-like handing of the search terms. Many hits is not an issue: hits are by default ordered on descending score. True to request making modifications to the query for AND-like behaviour. This may for example reduce the number of hits by a factor 10.
- "from": 0, "size": 10. Requests 10 documents at offset 0: requests to skip 0 documents and to return 10 documents that follow.
- "sort". Optional array of sort entries. If omitted the sort is on descending score.
- Field name. Use an actual field name, or use a special field name "_score" for the textual score, or "_doc" for the order as present in the Elastic index. Sorting on "_doc" is equivalent to sorting on "system_number".
- Order. Use "ascending" or "descending", or any abbreviation such as "asc" or "desc", or "a" or "d". If omitted it will be descending for "_score" and it will be ascending for all other fields.
- Multiple sort entries are possible and will be applied in order. Note that the above example is not too meaningful because sorting on a date field is a sort on a value with a ms resolution, which almost fully establishes the document order. Sorting on textual score within equal dates has little effect. This is true likewise when sorting on score first and on date next.
- "_source" - "excludes". Optional list of property names, specifying properties not to be returned in property _source of a found document. For example do not return property doc_body. Property nested.doc_body addresses property doc_body of the first level of documents nested under the main document, if applicable.
- "aggregations" - TagsAggregation. Request to count the number of occurrences of the values of a field. Typically category-like fields fields are counted. The counts are for the search result, not the entire index. The search application can report the counts to the user, and can support to set or clear checkboxes per category. In a next search it is then possible to filter on categories.
- "size": 20. Requests to return 20 buckets with counts, or less. Default is 10.
- "friendly_name". Can be used for user interface purposes. The value does not travel to Elastic Search and the value does not affect the search result. Enterprise Search restores the value in the search result.
- "aggregations" - DateRangesAggregation. Request to count the number of occurrences of a date in a field, using buckets defined by a date range. Typically a document creation date field is counted. The counts are again for the search result, not the entire index. The search application can report the counts to the user, and can support to set or clear checkboxes per date range. In a next search it is then possible to filter on date ranges.
- "from" and/or "to" contain a date specfiication; refer to Date range search.
Result notes:
- "took": "13". Net search time in ms. This is measured within the cluster and this for example excludes network latency.
- "_source". Content of the fields of a found document. There are several additional fields, plus extra fields as configured by the search application, all omitted here.
- "aggregations". This is the result of the aggregation request described above.