Elasticsearch 쿼리 개요

15197 단어 Elasticsearch

소개



Elasticsearch에서는 검색이 가장 중요한 처리입니다.
전체 텍스트 검색을 통해 사용자가 원하는 정보를 위에 표시할 수 있는 것이 이상적입니다.
Google 엔진과 같은 강력한 것은 불가능하지만, 가까워지면 편리함이 높아집니다.

Leaf query(검색 기초)



1. term query(지정된 단어와 정확히 일치)



지정된 단어로 정확한 검색. boost 값으로 관련 점수의 증감을 조정할 수 있습니다.

사이트의 샘플:
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query": {
        "term": {
            "user": {
                "value": "Kimchy",
                "boost": 1.0
            }
        }
    }
}
'


2. range query



범위 검색
사이트의 샘플:
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query": {
        "range" : {
            "age" : {
                "gte" : 10,
                "lte" : 20,
                "boost" : 2.0
            }
        }
    }
}
'


3. macth query(분해된 단어가 모두 있다)



전체 텍스트 검색의 기초에서 일치 할 때 쿼리 문자 분석

사이트의 샘플:
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query": {
        "match" : {
            "message" : {
                "query" : "this is a test",
                "operator" : "and"
            }
        }
    }
}
'

Compound query(복합 조건 검색)



1. bool query




동사
개요
영어 설명


must
AND 검색. 그리고 스코어가 더해진다.
The clause (query) must appear in matching documents and will contribute to the score.

filter
AND 검색. 그러나 점수가 더해지지 않음
The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching.

should
OR 검색
The clause (query) should appear in the matching document.

must_not
NOT 검색
The clause (query) must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses are considered for caching. Because scoring is ignored, a score of 0 for all documents is returned.


사이트의 샘플:
curl -X POST "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "bool" : {
      "must" : {
        "term" : { "user" : "kimchy" }
      },
      "filter": {
        "term" : { "tag" : "tech" }
      },
      "must_not" : {
        "range" : {
          "age" : { "gte" : 10, "lte" : 20 }
        }
      },
      "should" : [
        { "term" : { "tag" : "wow" } },
        { "term" : { "tag" : "elasticsearch" } }
      ],
      "minimum_should_match" : 1,
      "boost" : 1.0
    }
  }
}
'


2. boosting query



관련도 검색입니다.
부정적인 쿼리와 일치하는 문서의 관련성 점수를 줄이면서 긍정적인 쿼리와 일치하는 문서를 반환합니다.

사이트의 샘플:
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query": {
        "boosting" : {
            "positive" : {
                "term" : {
                    "text" : "apple"
                }
            },
            "negative" : {
                 "term" : {
                     "text" : "pie tart fruit crumble tree"
                }
            },
            "negative_boost" : 0.5
        }
    }
}
'

· positive: 긍정적인 검색. 필수 항목입니다.
· negative: 부정적인 검색. 필수 항목입니다.
·negative_boost:0~1.0의 소수입니다. 관련 점수를 계산하는 숫자입니다.

표시 순위 제어에 중요한 쿼리입니다.

3. constant_score query



일치하는 문서는 boost로 설정한 숫자 점수를 반환합니다.

사이트의 샘플:
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query": {
        "constant_score" : {
            "filter" : {
                "term" : { "user" : "kimchy"}
            },
            "boost" : 1.2
        }
    }
}
'


・filter:필수 항목입니다.
・boost:옵션 항목입니다. 기본값은 1.0입니다.

4. dis_max query(Disjunction max query)



최고의 관련성 점수를 계산할 때 점수가 높아집니다.

사이트의 샘플:
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query": {
        "dis_max" : {
            "queries" : [
                { "term" : { "title" : "Quick pets" }},
                { "term" : { "body" : "Quick pets" }}
            ],
            "tie_breaker" : 0.7
        }
    }
}
'


· queries : 필수 항목입니다. 크리에의 배열입니다.
· tie_breaker : 옵션 항목입니다. 0~1.0의 소수입니다. 기본값은 0.0입니다.

5. function_score query



점수를 조정하는 쿼리입니다.

사이트의 샘플:
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query": {
        "function_score": {
          "query": { "match_all": {} },
          "boost": "5", 
          "functions": [
              {
                  "filter": { "match": { "test": "bar" } },
                  "random_score": {}, 
                  "weight": 23
              },
              {
                  "filter": { "match": { "test": "cat" } },
                  "weight": 42
              }
          ],
          "max_boost": 42,
          "score_mode": "max",
          "boost_mode": "multiply",
          "min_score" : 42
        }
    }
}
'


기능이 번잡하고 아래 페이지에 있습니다.
htps //w w. 에스 c. 코 / 구이 / 엔 / 에 s 치 c 세아 rch / 레후 렌세 / 쿠렌 t / 쿠에 ry-dsl 훗 c 치 온 - s 이것 쿠에 ry. HTML

score_mode:


boost_mode:


등등

전체 텍스트 검색



전체 텍스트 검색에 대한 자세한 내용은 아래 페이지에 있습니다.
htps //w w. 에스 c. 코/구이데/엔/에어 s치c세아 rch/레후에렌세/콰렌 t/푼-로 xt-쿠에리에 s. HTML

1. intervals query



기간 검색 등 자세한 내용은 아래 페이지에 있습니다.
htps //w w. 에스 c. 코/구이데/엔/에아 s 치c 세아 rch/레후에 렌세/쿤 t/쿠에 ry-dsl-니 rゔぁ ls-쿠에 ry. HTML

2. Match query



문자열, 숫자, 날짜, bool 등으로 일치하는 검색입니다. 자세한 내용은 아래 페이지에 있습니다.
htps //w w. 에스 c. 코/구이데/엔/에ぁs치c세아 rch/레후에렌세/쿤렌 t/쿠에 ry-dsl마 tch-쿠에 ry. HTML

3. Match boolean prefix query



4. Match phrase query



htps //w w. 에스 c. 코/구이데/엔/에ぁs치c세아 rch/레후에렌세/쿠렌 t/쿠에 ry-dsl-마 tch-쿠에 ry-ph 라세. HTML
정확도를 제어할 수 있습니다.
사이트의 샘플:
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query": {
        "match_phrase" : {
            "message" : {
                "query" : "this is a test",
                "analyzer" : "my_analyzer"
            }
        }
    }
}
'


5. Match phrase prefix query



6. Multi-match query



이름 그대로 여러 필드의 match 쿼리입니다.
사이트의 샘플:
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "multi_match" : {
      "query":    "Will Smith",
      "fields": [ "title", "*_name" ] 
    }
  }
}
'


7. Common Terms Query



8. Query string query



올바른 문법이 필요합니다.

사이트의 샘플:
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query": {
        "query_string" : {
            "query" : "(new york city) OR (big apple)",
            "default_field" : "content"
        }
    }
}
'


9. Simple query string query



query string query와 비슷하지만 문법 부정이라도 오류가 발생하지 않습니다.

사이트의 샘플:
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "simple_query_string" : {
        "query": "\"fried eggs\" +(eggplant | potato) -frittata",
        "fields": ["title^5", "body"],
        "default_operator": "and"
    }
  }
}
'


정확하고 히트하는 것은 여러가지 궁리가 필요합니다.

이상

좋은 웹페이지 즐겨찾기