Merge pull request #18441 from MaineC/docs/add_console_to_search_request_options
Docs/add console to search request options
This commit is contained in:
commit
072eb99c5a
|
@ -10,15 +10,21 @@ body. Here is an example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
$ curl -XGET 'http://localhost:9200/twitter/tweet/_count?q=user:kimchy'
|
||||
PUT /twitter/tweet/1?refresh
|
||||
{
|
||||
"user": "kimchy"
|
||||
}
|
||||
|
||||
$ curl -XGET 'http://localhost:9200/twitter/tweet/_count' -d '
|
||||
GET /twitter/tweet/_count?q=user:kimchy
|
||||
|
||||
GET /twitter/tweet/_count
|
||||
{
|
||||
"query" : {
|
||||
"term" : { "user" : "kimchy" }
|
||||
}
|
||||
}'
|
||||
}
|
||||
--------------------------------------------------
|
||||
//CONSOLE
|
||||
|
||||
NOTE: The query being sent in the body must be nested in a `query` key, same as
|
||||
the <<search-search,search api>> works
|
||||
|
@ -37,6 +43,7 @@ tweets from the twitter index for a certain user. The result is:
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// TESTRESPONSE
|
||||
|
||||
The query is optional, and when not provided, it will use `match_all` to
|
||||
count all the docs.
|
||||
|
|
|
@ -5,6 +5,7 @@ Enables explanation for each hit on how its score was computed.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"explain": true,
|
||||
"query" : {
|
||||
|
@ -12,3 +13,4 @@ Enables explanation for each hit on how its score was computed.
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
|
|
@ -6,13 +6,15 @@ example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query" : {
|
||||
...
|
||||
"match_all": {}
|
||||
},
|
||||
"fielddata_fields" : ["test1", "test2"]
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Field data fields can work on fields that are not stored.
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ by a search hit.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"fields" : ["user", "postDate"],
|
||||
"query" : {
|
||||
|
@ -18,6 +19,7 @@ by a search hit.
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
`*` can be used to load all stored fields from the document.
|
||||
|
||||
|
@ -26,6 +28,7 @@ returned, for example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"fields" : [],
|
||||
"query" : {
|
||||
|
@ -33,6 +36,7 @@ returned, for example:
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
|
||||
For backwards compatibility, if the fields parameter specifies fields which are not stored (`store` mapping set to
|
||||
|
|
|
@ -8,6 +8,7 @@ graph where each user has an index).
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"indices_boost" : {
|
||||
"index1" : 1.4,
|
||||
|
@ -15,3 +16,4 @@ graph where each user has an index).
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
|
|
@ -6,6 +6,7 @@ in `min_score`:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"min_score": 0.5,
|
||||
"query" : {
|
||||
|
@ -13,6 +14,7 @@ in `min_score`:
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Note, most times, this does not make much sense, but is provided for
|
||||
advanced use cases.
|
||||
|
|
|
@ -5,7 +5,9 @@ Each filter and query can accept a `_name` in its top level definition.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"should" : [
|
||||
{"match" : { "name.first" : {"query" : "shay", "_name" : "first"} }},
|
||||
|
@ -19,7 +21,9 @@ Each filter and query can accept a `_name` in its top level definition.
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
The search response will include for each hit the `matched_queries` it matched on. The tagging of queries and filters
|
||||
only make sense for the `bool` query.
|
||||
|
|
|
@ -5,14 +5,43 @@ The `post_filter` is applied to the search `hits` at the very end of a search
|
|||
request, after aggregations have already been calculated. Its purpose is
|
||||
best explained by example:
|
||||
|
||||
Imagine that you are selling shirts, and the user has specified two filters:
|
||||
Imagine that you are selling shirts that have the following properties:
|
||||
|
||||
[source,js]
|
||||
-------------------------------------------------
|
||||
PUT /shirts
|
||||
{
|
||||
"mappings": {
|
||||
"item": {
|
||||
"properties": {
|
||||
"brand": { "type": "keyword"},
|
||||
"color": { "type": "keyword"},
|
||||
"model": { "type": "keyword"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PUT /shirts/item/1?refresh
|
||||
{
|
||||
"brand": "gucci",
|
||||
"color": "red",
|
||||
"model": "slim"
|
||||
}
|
||||
------------------------------------------------
|
||||
// CONSOLE
|
||||
// TESTSETUP
|
||||
|
||||
|
||||
Imagine a user has specified two filters:
|
||||
|
||||
`color:red` and `brand:gucci`. You only want to show them red shirts made by
|
||||
Gucci in the search results. Normally you would do this with a
|
||||
<<query-dsl-bool-query,`bool` query>>:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
curl -XGET localhost:9200/shirts/_search -d '
|
||||
GET /shirts/_search
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
|
@ -23,8 +52,8 @@ curl -XGET localhost:9200/shirts/_search -d '
|
|||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
However, you would also like to use _faceted navigation_ to display a list of
|
||||
other options that the user could click on. Perhaps you have a `model` field
|
||||
|
@ -36,7 +65,7 @@ This can be done with a
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
curl -XGET localhost:9200/shirts/_search -d '
|
||||
GET /shirts/_search
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
|
@ -52,8 +81,8 @@ curl -XGET localhost:9200/shirts/_search -d '
|
|||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
<1> Returns the most popular models of red shirts by Gucci.
|
||||
|
||||
But perhaps you would also like to tell the user how many Gucci shirts are
|
||||
|
@ -67,12 +96,12 @@ the `post_filter`:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
curl -XGET localhost:9200/shirts/_search -d '
|
||||
GET /shirts/_search
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": {
|
||||
{ "term": { "brand": "gucci" }} <1>
|
||||
"term": { "brand": "gucci" } <1>
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -95,8 +124,8 @@ curl -XGET localhost:9200/shirts/_search -d '
|
|||
"term": { "color": "red" }
|
||||
}
|
||||
}
|
||||
'
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
<1> The main query now finds all shirts by Gucci, regardless of color.
|
||||
<2> The `colors` agg returns popular colors for shirts by Gucci.
|
||||
<3> The `color_red` agg limits the `models` sub-aggregation
|
||||
|
|
|
@ -56,7 +56,7 @@ for the user:
|
|||
|
||||
[source,js]
|
||||
------------------------------------------------
|
||||
curl localhost:9200/_search?preference=xyzabc123 -d '
|
||||
GET /_search?preference=xyzabc123
|
||||
{
|
||||
"query": {
|
||||
"match": {
|
||||
|
@ -64,7 +64,6 @@ curl localhost:9200/_search?preference=xyzabc123 -d '
|
|||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
------------------------------------------------
|
||||
|
||||
// CONSOLE
|
||||
|
||||
|
|
|
@ -6,9 +6,11 @@ query using the <<query-dsl,Query DSL>>.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query" : {
|
||||
"term" : { "user" : "kimchy" }
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
|
|
@ -6,9 +6,10 @@ evaluation>> (based on different fields) for each hit, for example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query" : {
|
||||
...
|
||||
"match_all": {}
|
||||
},
|
||||
"script_fields" : {
|
||||
"test1" : {
|
||||
|
@ -25,6 +26,8 @@ evaluation>> (based on different fields) for each hit, for example:
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
|
||||
Script fields can work on fields that are not stored (`my_field_name` in
|
||||
the above case), and allow to return custom values to be returned (the
|
||||
|
@ -36,9 +39,10 @@ type). Here is an example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query" : {
|
||||
...
|
||||
"match_all": {}
|
||||
},
|
||||
"script_fields" : {
|
||||
"test1" : {
|
||||
|
@ -47,6 +51,7 @@ type). Here is an example:
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Note the `_source` keyword here to navigate the json-like model.
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ To disable `_source` retrieval set to `false`:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"_source": false,
|
||||
"query" : {
|
||||
|
@ -20,6 +21,7 @@ To disable `_source` retrieval set to `false`:
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
The `_source` also accepts one or more wildcard patterns to control what parts of the `_source` should be returned:
|
||||
|
||||
|
@ -27,6 +29,7 @@ For example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"_source": "obj.*",
|
||||
"query" : {
|
||||
|
@ -34,11 +37,13 @@ For example:
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Or
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"_source": [ "obj1.*", "obj2.*" ],
|
||||
"query" : {
|
||||
|
@ -46,11 +51,13 @@ Or
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Finally, for complete control, you can specify both include and exclude patterns:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"_source": {
|
||||
"include": [ "obj1.*", "obj2.*" ],
|
||||
|
@ -61,3 +68,4 @@ Finally, for complete control, you can specify both include and exclude patterns
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
|
|
@ -5,6 +5,7 @@ Returns a version for each search hit.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"version": true,
|
||||
"query" : {
|
||||
|
@ -12,3 +13,4 @@ Returns a version for each search hit.
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
|
Loading…
Reference in New Issue