elasticsearch cmd2
4568 단어 elasticsearch
Going back to our last example, we executed this query:
GET /bank/_search
{
"query": { "match_all": {} }
}
In addition to the
query
parameter, we also can pass other parameters to influence the search results. In the example in the section above we passed in sort
, here we pass in size
: GET /bank/_search
{
"query": { "match_all": {} },
"size": 1
}
Note that if
size
is not specified, it defaults to 10. This example does a
match_all
and returns documents 10 through 19: GET /bank/_search
{
"query": { "match_all": {} },
"from": 10,
"size": 10
}
This example does a
match_all
and sorts the results by account balance in descending order and returns the top 10 (default size) documents. GET /bank/_search
{
"query": { "match_all": {} },
"sort": { "balance": { "order": "desc" } }
}
Executing Searches
This example shows how to return two fields,
account_number
and balance
(inside of _source
), from the search: GET /bank/_search
{
"query": { "match_all": {} },
"_source": ["account_number", "balance"]
}
Now let’s move on to the query part. Previously, we’ve seen how the
match_all
query is used to match all documents. Let’s now introduce a new query called the match
query, which can be thought of as a basic fielded search query (i.e. a search done against a specific field or set of fields). This example returns the account numbered 20:
GET /bank/_search
{
"query": { "match": { "account_number": 20 } }
}
This example returns all accounts containing the term "mill"in the address:
GET /bank/_search
{
"query": { "match": { "address": "mill" } }
}
Let’s now introduce the
bool
query. The bool
query allows us to compose smaller queries into bigger queries using boolean logic. This example composes two
match
queries and returns all accounts containing "mill"and "lane"in the address: GET /bank/_search
{
"query": {
"bool": {
"must": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }
]
}
}
}
In the above example, the
bool must
clause specifies all the queries that must be true for a document to be considered a match. In contrast, this example composes two
match
queries and returns all accounts containing "mill"or "lane"in the address: GET /bank/_search
{
"query": {
"bool": {
"should": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }
]
}
}
}
This example composes two
match
queries and returns all accounts that contain neither "mill"nor "lane"in the address: GET /bank/_search
{
"query": {
"bool": {
"must_not": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }
]
}
}
}
We can combine
must
, should
, and must_not
clauses simultaneously inside a bool
query. Furthermore, we can compose bool
queries inside any of these bool
clauses to mimic any complex multi-level boolean logic. This example returns all accounts of anybody who is 40 years old but doesn’t live in ID(aho):
GET /bank/_search
{
"query": {
"bool": {
"must": [
{ "match": { "age": "40" } }
],
"must_not": [
{ "match": { "state": "ID" } }
]
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
kafka connect e elasticsearch를 관찰할 수 있습니다.No menu lateral do dashboard tem a opção de connectors onde ele mostra todos os clusters do kafka connect conectados atu...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.