반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

[900gle] elasticsearch 검색쿼리 본문

900gle shopping/system

[900gle] elasticsearch 검색쿼리

닉의네임 2022. 1. 15. 14:59
반응형

쿼리 구조

phase 1

 

 

phase 2

 

 

phase 3

 

phase 4

 

phase 5

 

쿼리 셈플

phase 2 query 

script_query = {
        "function_score": {
            "query": {
                "bool": {
                    "must": [
                        {
                            "multi_match": {
                                "query": query,
                                "fields": [
                                    "name",
                                    "category"
                                ]
                            }
                        }],
                    "should": [
                        {
                            "multi_match": {
                                "query": query,
                                "fields": [
                                    "category1",
                                    "category2",
                                    "category3",
                                    "category4",
                                    "category5"
                                ]
                            }
                        }
                    ]
                }
            },
            "boost_mode": "multiply",
            "functions": [
                {
                    "script_score": {
                        "script": {
                            "source": "cosineSimilarity(params.query_vector, 'feature_vector') * doc['weight'].value * doc['popular'].value / doc['name.keyword'].length + doc['category.keyword'].length",
                            "params": {
                                "query_vector": query_vector
                            }
                        }
                    },
                    "weight": 0.1
                }
            ]
        }
    }

 

{
   "query":{
      "function_score":{
         "query":{
            "multi_match":{
               "query":"나이키",
               "fields":[
                  "name^5",
                  "category"
               ]
            }
         },
         "functions":[
            {
               "script_score":{
                  "script":{
                     "source":"cosineSimilarity(params.query_vector, doc['name_vector']) + 1.0",
                     "params":{
                        "query_vector":[
                           0.0008812982123345137,
                           0.026942647993564606,
                           ".....",
                           0.08682870119810104,
                           0.02672387659549713
                        ]
                     }
                  }
               },
               "weight":50
            },
            {
               "filter":{
                  "match":{
                     "name":"나이키"
                  }
               },
               "random_score":{
                  
               },
               "weight":23
            }
         ]
      }
   },
   "sort":[
      {
         "_script":{
            "type":"number",
            "order":"desc",
            "script":{
               "source":"doc['price'].value / params.searchKeyword",
               "params":{
                  "searchKeyword":10000
               }
            }
         }
      },
      {
         "price":{
            "order":"asc"
         }
      }
   ]
}
반응형

'900gle shopping > system' 카테고리의 다른 글

[900gle] Architecture  (0) 2022.01.05
Comments