반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

[es] 검색쿼리를 만들어 보자 2 본문

ElasticStack/Elasticsearch

[es] 검색쿼리를 만들어 보자 2

닉의네임 2022. 1. 29. 00:58
반응형

https://www.elastic.co/guide/en/elasticsearch/reference/current/similarity.html

 

similarity | Elasticsearch Guide [7.16] | Elastic

Elasticsearch allows you to configure a scoring algorithm or similarity per field. The similarity setting provides a simple way of choosing a similarity algorithm other than the default BM25, such as TF/IDF. Similarities are mostly useful for text fields,

www.elastic.co

이건 또 뭐꼬.. 

할게 너무 많네

 

PUT /index?pretty
{
  "settings": {
    "number_of_shards": 1,
    "similarity": {
      "scripted_tfidf": {
        "type": "scripted",
        "script": {
          "source": "double tf = Math.sqrt(doc.freq); double idf = Math.log((field.docCount+1.0)/(term.docFreq+1.0)) + 1.0; double norm = 1/Math.sqrt(doc.length); return query.boost * tf * idf * norm;"
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "field": {
        "type": "text",
        "similarity": "scripted_tfidf"
      }
    }
  }
}


PUT /index/_doc/1?pretty
{
  "field": "foo bar foo"
}


PUT /index/_doc/2?pretty
{
  "field": "bar baz"
}


POST /index/_refresh?pretty
GET /index/_search?explain=true&pretty
{
  "query": {
    "query_string": {
      "query": "foo^1.7",
      "default_field": "field"
    }
  }
}
반응형
Comments