2.X/2. Search in Depth

2-2-1. Term-Based Versus Full-Text

drscg 2017. 9. 30. 01:48

While all queries perform some sort of relevance calculation, not all queries have an analysis phase.Besides specialized queries like the bool or function_score queries, which don’t operate on text at all, textual queries can be broken down into two families:

모든 query가 relevance 연산의 일종을 수행하지만, 모든 query가 analysis 절을 가지지는 않는다. 텍스트를 전혀 다루지 않는, bool 이나 function-score query 같은 특별한 query 이외에, 텍스트를 다루는 query는 두 가지로 분류될 수 있다.

단어 기반의 query

Queries like the term or fuzzy queries are low-level queries that have no analysis phase. They operate on a single term. A term query for the term Foo looks for that exact term in the inverted index and calculates the TF/IDF relevance _score for each document that contains the term.

term 이나 fuzzy query 같은 query들은, analysis 단계가 없는, low-level query 들이다. 그들은 하나의 단어만을 다룬다. Foo 라는 단어를 찾는 term query는, inverted index에서 정확히 똑같은 단어(exact term) 만을 찾고, 해당 단어를 포함하고 있는, 각 document를 위한 TF/IDF relevance _score를 계산한다.

It is important to remember that the term query looks in the inverted index for the exact term only; it won’t match any variants like foo or FOO. It doesn’t matter how the term came to be in the index, just that it is. If you were to index ["Foo","Bar"] into an exact value not_analyzedfield, or Foo Bar into an analyzed field with the whitespace analyzer, both would result in having the two terms Foo and Bar in the inverted index.

term query가 inverted index에서 정확한 단어만을 찾는다는 것을 기억하는 것이 중요하다. fooFOO같은 다른 변형은 일치하지 않을 것이다. 그 단어가 어떻게 index에 있는지는 중요하지 않고, 단지 그것이 존재한다는 것이 중요하다. not_analyzed field에 ["Foo","Bar"] 를 exact value으로 색인했거나, whitespace analyzer로 analyzed field에 Foo Bar 를 색인했다면, 위의 두 경우 모두는 inverted index에 Foo 와 Bar 라는 두 단어를 가지게 된다.

Full-text queries

Queries like the match or query_string queries are high-level queries that understand the mapping of a field:

match 나 query_string 같은 query들은, field mapping을 이해하는, high-level query이다.

  • If you use them to query a date or integer field, they will treat the query string as a date or integer, respectively.

    date 나 integer field를 query하면, query string을 date나 integer 각각으로 취급한다.

  • If you query an exact value (not_analyzed) string field, they will treat the whole query string as a single term.

    exact value(not_analyzed) string field를 query하면, 전체 query string을 단일 단어로 취급한다.

  • But if you query a full-text (analyzed) field, they will first pass the query string through the appropriate analyzer to produce the list of terms to be queried.

    그러나, full-text(analyzed) field를 query하면, query string을 query할 단어의 목록을 만들어 내기 위하여, 적절한 analyzer로 먼저 전달한다.

Once the query has assembled a list of terms, it executes the appropriate low-level query for each of these terms, and then combines their results to produce the final relevance score for each document.

일단, query가 단어 목록을 가지게 되면, 이들 단어 각각에 대해, 적절한 low-level query를 실행한다. 그리고 나서, 각각의 document에 대한 최종 relevance score를 만들어내기 위해, 결과를 조합한다.

We will discuss this process in more detail in the following chapters.

다음 장에서, 이 과정에 대해 좀 더 자세히 언급할 것이다.

You seldom need to use the term-based queries directly. Usually you want to query full text, not individual terms, and this is easier to do with the high-level full-text queries (which end up using term-based queries internally).

단어 기반의 query를 직접적으로 사용하는 경우는 거의 없다. 일반적으로 개별단어가 아닌, full-text query를 사용한다. 또, high-level full-text query가 더 쉽다. 결국에는, 내부적으로 단어 기반의 query를 사용한다.

Note

If you do find yourself wanting to use a query on an exact value not_analyzed field, think about whether you really want a scoring query, or if a non-scoring query might be better.

exact value not_analyzed field에서 query하려고 한다면, 실제로 scoring query를 원하는지, 또는 non-scoring query가 더 나을지를 생각해 봐야 한다.

Single-term queries usually represent binary yes/no questions and are almost always better expressed as a filter, so that they can benefit from caching:

일반적으로 단일 단어 query는 yes/no 질문을 나타내고, 거의 항상 filter로 표현되는 것이 더 좋다. 왜냐하면 caching의 이점이 있기 때문이다.

GET /_search
{
    "query": {
        "constant_score": {
            "filter": {
                "term": { "gender": "female" }
            }
        }
    }
}


'2.X > 2. Search in Depth' 카테고리의 다른 글

2-1-6. All About Caching  (0) 2017.09.30
2-2. Full-Text Search  (0) 2017.09.30
2-2-2. The match Query  (0) 2017.09.30
2-2-3. Multiword Queries  (0) 2017.09.30
2-2-4. Combining Queries  (0) 2017.09.30