반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

[es] sort - payload sort 본문

ElasticStack/Elasticsearch

[es] sort - payload sort

닉의네임 2022. 6. 30. 16:30
반응형

Elasticsearch 7.9.2 에 payload plugin 설치

 

settings

{
  "home-leaflet_2022.06.30.16.20" : {
    "settings" : {
      "index" : {
        "search" : {
          "slowlog" : {
            "threshold" : {
              "fetch" : {
                "warn" : "3s"
              },
              "query" : {
                "warn" : "3s"
              }
            }
          }
        },
        "refresh_interval" : "5s",
        "number_of_shards" : "3",
        "provided_name" : "home-leaflet_2022.06.30.16.20",
        "creation_date" : "1656573604579",
        "analysis" : {
          "analyzer" : {
            "payload_delimiter" : {
              "filter" : [
                "delimited_payload"
              ],
              "encoding" : "int",
              "delimiter" : "|",
              "tokenizer" : "whitespace"
            }
          }
        },
        "number_of_replicas" : "1",
        "uuid" : "dmCx0DLMROelfGV0Clvk9A",
        "version" : {
          "created" : "7090299"
        }
      }
    }
  }
}

 

mapping

 

        "leafletInfos" : {
          "type" : "text",
          "term_vector" : "with_positions_payloads",
          "analyzer" : "payload_delimiter"
        }

 

Query

GET home-leaflet/_search
{
  "_source": [
    "itemNm",
    "leafletInfos",
    "itemStoreInfo.weight",
    "itemStoreInfo.weightCalc",
    "itemStoreInfo.weightCalcDetail"
  ],
  "from": 0,
  "size": 1,
  "timeout": "60s",
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "saleStartDt": {
              "from": null,
              "to": "now/m",
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        },
        {
          "range": {
            "saleEndDt": {
              "from": "now/m",
              "to": null,
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        },
        {
          "bool": {
            "should": [
              {
                "terms": {
                  "itemStoreInfo.storeId": [
                    "37",
                    "20163"
                  ],
                  "boost": 1
                }
              },
              {
                "terms": {
                  "shipMethod": [
                    "TD_DLV"
                  ],
                  "boost": 1
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "term": {
            "leafletInfos": {
              "value": "84_1",
              "boost": 1
            }
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  },
  "sort": [
    {
      "_script": {
        "script": {
          "source": "payload_sort",
          "lang": "sort_script",
          "params": {
            "field": "leafletInfos",
            "value": "84_1"
          }
        },
        "type": "number",
        "order": "asc"
      }
    }
  ],
  "track_total_hits": -1
}

Result 

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "max_score" : null,
    "hits" : [
      {
        "_index" : "home-leaflet_2022.06.30.16.30",
        "_type" : "_doc",
        "_id" : "jxmFs4EBYEOCs0V9yuf7",
        "_score" : null,
        "_source" : {
          "leafletInfos" : "84_19|3 84_1|0",
          "itemNm" : "일품포크 돼지삼겹살 100G/돼지고기",
          "itemStoreInfo" : {
            "weightCalcDetail" : {
              "openDayWeight" : 1.0,
              "buyerWeight" : 72.0,
              "buyerCntHour" : 72,
              "priceWeight" : 1.0,
              "storeTypeWeight" : 1.0,
              "shipTypeWeight" : 1.0,
              "groupWeight" : null,
              "benefitWeight" : 1.0,
              "eventWeight" : 1.0
            },
            "weightCalc" : "...",
            "weight" : 72.0
          }
        },
        "sort" : [
          0.0
        ]
      }
    ]
  }
}
반응형

'ElasticStack > Elasticsearch' 카테고리의 다른 글

[es] sort - payload sort 2  (0) 2022.07.03
[es] script similarity test phase 2  (0) 2022.07.03
[es] script similarity test  (0) 2022.06.26
[es] scripted similarity  (0) 2022.06.24
[es] Similarity module  (0) 2022.06.24
Comments