首页  

elasticsearch5.0使用RequestBody搜索接口     所属分类 elasticsearch 浏览量 1195
根据原文翻译整理
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/search-request-body.html


The search request can be executed with a search DSL, 
which includes the Query DSL, within its body.

Query DSL
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl.html


Query DSL 使用json格式 

GET /twitter/tweet/_search
{
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

Out of the above, the search_type and the request_cache must be passed as query-string parameters. 
The rest of the search request should be passed within the body itself. 
The body content can also be passed as a REST parameter named source.

search_type和request_cache必须作为查询字符串参数传递。
其余部分应该在body中传递
主体内容也可以作为一个名为source的REST参数传递

Both HTTP GET and HTTP POST can be used to execute search with body. 
Since not all clients support GET with body, POST is allowed as well.

HTTP GET和HTTP POST都可以使用body执行搜索。
因为不是所有的客户端都支持GET with body,所以POST也是允许的。


Fast check for any matching docs
快速检查是否匹配到文档了


GET /_search?q=message:elasticsearch&size=0&terminate_after=1

if the query was terminated early, the terminated_early flag will be set to true in the response.
 
terminated_early

{
    "from" : 0, "size" : 10,
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

"sort" : [
        { "post_date" : {"order" : "asc"}},
        "user",
        { "name" : "desc" },
        { "age" : "desc" },
        "_score"
    ],
    
_score to sort by score  根据文档分数排序
_doc to sort by index order 根据文档索引顺序排序


_doc has no real use-case besides being the most efficient sort order. 
So if you don’t care about the order in which documents are returned, 
then you should sort by _doc. This especially helps when scrolling.

_doc除了是最有效的排序顺序之外,没有真正的用例。
因此,如果您不关心文档返回的顺序,那么应该按_doc排序。这在滚动时特别有用。

supports sorting by array or multi-valued fields. 
数组和多个值字段的排序

min max avg sum

PUT /my_index/my_type/1?refresh
{
   "product": "chocolate",
    "price": [20, 4]
}

POST /_search
{
   "query" : {
      "term" : { "product" : "chocolate" }
   },
   "sort" : [
      {"price" : {"order" : "asc", "mode" : "avg"}}
   ]
}

Missing Values
missing value can be set to _last, _first, or a custom value

By default, the search request will fail if there is no mapping associated with a field. 

默认情况下,如果没有与字段关联的映射,搜索请求将失败。
"sort" : [
        { "price" : {"unmapped_type" : "long"} }
    ]

Script Based Sorting
基于脚本的排序


Geo Distance Sorting


geo distance sorting does not support configurable missing values

Lat Lon as Properties   string  geohash array

distance_type
sloppy_arc arc plane


_source field 筛选 过滤

"_source": false   obj.*  [ "obj1.*", "obj2.*" ]  ["field1","field2"]
includes and excludes patterns


The stored_fields parameter is about fields that are explicitly marked as stored in the mapping, 
which is off by default and generally not recommended.


If the requested fields are not stored (store mapping set to false), they will be ignored.

脚本字段 
Script fields can work on fields that are not stored 

script_fields
"test1" : {
            "script" : {
                "lang": "painless",
                "inline": "doc['my_field_name'].value * 2"
            }
        }
        
使用doc仍然是访问文档值的推荐方法,因为每次使用_source时都必须加载和解析它。使用_source非常慢。

Doc value Fields
Doc value fields can work on fields that are not stored.


Note that if the fields parameter specifies fields without docvalues 
it will try to load the value from the fielddata cache 
causing the terms for that field to be loaded to memory (cached), 
which will result in more memory consumption.

如果fields参数指定了没有docvalues的字段,它将尝试从fielddata缓存加载该值,
从而导致将该字段的词加载到内存(缓存)中,这将导致更多内存消耗。

Post filter
The post_filter is applied to the search hits at the very end of a search request, 
after aggregations have already been calculated. 

搜索结果过滤,在搜索执行之后再过滤

Allows to highlight search results on one or more fields. 

lucene plain highlighter
the fast vector highlighter (fvh) 
postings highlighter


Rescoring

Search Type
There are different execution paths that can be done when executing a distributed search. 
The distributed search operation needs to be scattered to all the relevant shards 
and then all the results are gathered back. 
When doing scatter/gather type execution, there are several ways to do that, 
specifically with search engines.

query_then_fetch
dfs_query_then_fetch

scroll


"explain": true

返回结果显示文档,默认为false
"version": true

上一篇     下一篇
elasticsearch5.0搜索API使用概述

elasticsearch5.0基于url的搜索接口

新东方年会《释放自我》歌词

科创板首批人工智能公司信息

CAP和一致性协议

MySQL基础架构