すべてのクエリに一致

最も単純なクエリで、すべてのドキュメントに一致し、すべてに _score1.0 を与えます。

Php

  1. $params = [
  2. 'body' => [
  3. 'query' => [
  4. 'match_all' => [
  5. ],
  6. ],
  7. ],
  8. ];
  9. $response = $client->search($params);

Python

  1. resp = client.search(
  2. query={
  3. "match_all": {}
  4. },
  5. )
  6. print(resp)

Ruby

  1. response = client.search(
  2. body: {
  3. query: {
  4. match_all: {}
  5. }
  6. }
  7. )
  8. puts response

Go

  1. res, err := es.Search(
  2. es.Search.WithBody(strings.NewReader(`{
  3. "query": {
  4. "match_all": {}
  5. }
  6. }`)),
  7. es.Search.WithPretty(),
  8. )
  9. fmt.Println(res, err)

Js

  1. const response = await client.search({
  2. query: {
  3. match_all: {},
  4. },
  5. });
  6. console.log(response);

Console

  1. GET /_search
  2. {
  3. "query": {
  4. "match_all": {}
  5. }
  6. }

_scoreboost パラメータで変更できます:

Python

  1. resp = client.search(
  2. query={
  3. "match_all": {
  4. "boost": 1.2
  5. }
  6. },
  7. )
  8. print(resp)

Ruby

  1. response = client.search(
  2. body: {
  3. query: {
  4. match_all: {
  5. boost: 1.2
  6. }
  7. }
  8. }
  9. )
  10. puts response

Go

  1. res, err := es.Search(
  2. es.Search.WithBody(strings.NewReader(`{
  3. "query": {
  4. "match_all": {
  5. "boost": 1.2
  6. }
  7. }
  8. }`)),
  9. es.Search.WithPretty(),
  10. )
  11. fmt.Println(res, err)

Js

  1. const response = await client.search({
  2. query: {
  3. match_all: {
  4. boost: 1.2,
  5. },
  6. },
  7. });
  8. console.log(response);

Console

  1. GET /_search
  2. {
  3. "query": {
  4. "match_all": { "boost" : 1.2 }
  5. }
  6. }

一致しないクエリ

これは match_all クエリの逆で、ドキュメントに一致しません。

Python

  1. resp = client.search(
  2. query={
  3. "match_none": {}
  4. },
  5. )
  6. print(resp)

Ruby

  1. response = client.search(
  2. body: {
  3. query: {
  4. match_none: {}
  5. }
  6. }
  7. )
  8. puts response

Go

  1. res, err := es.Search(
  2. es.Search.WithBody(strings.NewReader(`{
  3. "query": {
  4. "match_none": {}
  5. }
  6. }`)),
  7. es.Search.WithPretty(),
  8. )
  9. fmt.Println(res, err)

Js

  1. const response = await client.search({
  2. query: {
  3. match_none: {},
  4. },
  5. });
  6. console.log(response);

Console

  1. GET /_search
  2. {
  3. "query": {
  4. "match_none": {}
  5. }
  6. }