5AMSUNG

[es] _explain 본문

Elastic Stack/elasticsearch

[es] _explain

짝구이 2023. 5. 9. 18:20
반응형

아마도 이런 스타일의 글 때문에도 애드센스 심사에서 빠꾸를 먹는것 같다.

구백글은 쉽게 받았는데 .. 젠장..

 

자주쓰는 명령어를 모아보잣

 

_termvectors

색인된 도큐먼트의 역 인덱스의 내용을 확인할 때는 도큐먼트 별로 _termvectors API를이용해서 확인

GET <인덱스>/_termvectors/<도큐먼트id>?fields=<필드명>

 

_explain

특정 문서가 쿼리와 일치하는(또는 일치하지 않는) 이유에 대한 정보를 반환합니다.

GET /<index>/_explain/<id>

POST /<index>/_explain/<id>

 

_analyze

Elasticsearch 에서는 분석된 문장을 _analyze API를 이용해서 확인할 수 있습니다. 토크나이저는 tokenizer, 토큰 필터는 filter 항목의 값으로 입력하면 됩니다. 토크나이저는 하나만 적용되기 때문에 바로 입력하고, 토큰필터는 여러개를 적용할 수 있기 때문에 [ ] 안에 배열 형식으로 입력

#_termvectors
GET hyper-item/_termvectors/1657301588000FA6F960FF6852F49090B7451CB85EC2E?fields=searchItemNm

#_explain
GET hyper-item/_doc/1657301588000FA6F960FF6852F49090B7451CB85EC2E/_explain
{
    "query" :{
    }
}

#_analyze
POST hyper-item/_analyze
{
  "analyzer": "index_analyzer",
  "text": "_마티니로쏘_750ML"
}


POST hyper-item/_analyze
{
  "analyzer": "search_analyzer",
  "text": "과자"
}


POST _analyze
{
  "tokenizer": "standard",
  "filter":  [ "lowercase", "asciifolding" ],
  "text":      "Is this déja vu?"
}

과자를 검색하면 와인이 걸리는 ..

일단 이슈는 상품명이 저렇게 생겼는데 ..

상품명

다양한 뻘짓을 통해 이유는 알아냈지만 

좀 편하게 알아내는 법이 없을까..

 

 

 

 

 

상품명의 텀

{
  "_index" : "hyper-item_2023.05.09.14.57",
  "_type" : "_doc",
  "_id" : "1657301588000FA6F960FF6852F49090B7451CB85EC2E",
  "_version" : 2,
  "found" : true,
  "took" : 0,
  "term_vectors" : {
    "searchItemNm" : {
      "field_statistics" : {
        "sum_doc_freq" : 16173194,
        "doc_count" : 1844854,
        "sum_ttf" : 18146375
      },
      "terms" : {
        "750" : {
          "term_freq" : 1,
          "tokens" : [
            {
              "position" : 5,
              "start_offset" : 15,
              "end_offset" : 18
            }
          ]
        },
        "750ml" : {
          "term_freq" : 1,
          "tokens" : [
            {
              "position" : 6,
              "start_offset" : 15,
              "end_offset" : 20
            }
          ]
        },
        "ml" : {
          "term_freq" : 1,
          "tokens" : [
            {
              "position" : 7,
              "start_offset" : 18,
              "end_offset" : 20
            }
          ]
        },
        "드라이" : {
          "term_freq" : 1,
          "tokens" : [
            {
              "position" : 2,
              "start_offset" : 5,
              "end_offset" : 8
            }
          ]
        },
        "로" : {
          "term_freq" : 1,
          "tokens" : [
            {
              "position" : 1,
              "start_offset" : 3,
              "end_offset" : 4
            }
          ]
        },
        "로쏘" : {
          "term_freq" : 1,
          "tokens" : [
            {
              "position" : 4,
              "start_offset" : 12,
              "end_offset" : 14
            }
          ]
        },
        "비노" : {
          "term_freq" : 1,
          "tokens" : [
            {
              "position" : 3,
              "start_offset" : 9,
              "end_offset" : 11
            }
          ]
        },
        "프레첼" : {
          "term_freq" : 1,
          "tokens" : [
            {
              "position" : 0,
              "start_offset" : 0,
              "end_offset" : 3
            }
          ]
        }
      }
    }
  }
}

쿼리 explain 

GET hyper-item/_doc/1657301588000FA6F960FF6852F49090B7451CB85EC2E/_explain
{
  "query": {
    "bool": {
      "must": [
        {
          "function_score": {
            "query": {
              "multi_match": {
                "query": "과자",
                "fields": [
                  "brandNmEng^1.0",
                  "brandNmKor^1.0",
                  "category.categorySearchKeyword^1.0",
                  "category.dcateNm^1.0",
                  "isbn^1.0",
                  "itemNo^1.0",
                  "itemOptionNms^1.0",
                  "itemStoreInfo.eventInfo.eventKeyword^1.0",
                  "promoKeyword^1.0",
                  "searchItemNm^1.0",
                  "searchKeyword^1.0"
                ],
                "type": "cross_fields",
                "operator": "AND",
                "slop": 0,
                "prefix_length": 0,
                "max_expansions": 50,
                "zero_terms_query": "NONE",
                "auto_generate_synonyms_phrase_query": false,
                "fuzzy_transpositions": true,
                "boost": 1
              }
            },
            "functions": [
              {
                "filter": {
                  "match_all": {
                    "boost": 1
                  }
                },
                "weight": 0
              },
              {
                "filter": {
                  "match_all": {
                    "boost": 1
                  }
                },
                "script_score": {
                  "script": {
                    "source": "category_boost_df",
                    "lang": "boost_script",
                    "params": {
                      "operation_score": 1000,
                      "field": "category.cateCdGroup",
                      "category_id": "200095",
                      "default_score": 1000,
                      "operation_mode": "+"
                    }
                  }
                }
              },
              {
                "filter": {
                  "match_all": {
                    "boost": 1
                  }
                },
                "script_score": {
                  "script": {
                    "source": "category_boost_df",
                    "lang": "boost_script",
                    "params": {
                      "operation_score": 1000,
                      "field": "category.cateCdGroup",
                      "category_id": "300633",
                      "default_score": 1000,
                      "operation_mode": "+"
                    }
                  }
                }
              }
            ],
            "score_mode": "sum",
            "boost_mode": "replace",
            "max_boost": 3.4028235e+38,
            "boost": 1
          }
        }
      ],
      "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
            }
          }
        },
        {
          "multi_match": {
            "query": "Y",
            "fields": [
              "docDispYn^1.0",
              "rsvDocDispYn^1.0"
            ],
            "type": "best_fields",
            "operator": "OR",
            "slop": 0,
            "prefix_length": 0,
            "max_expansions": 50,
            "zero_terms_query": "NONE",
            "auto_generate_synonyms_phrase_query": true,
            "fuzzy_transpositions": true,
            "boost": 1
          }
        },
        {
          "bool": {
            "should": [
              {
                "terms": {
                  "itemStoreInfo.storeId": [
                    "37",
                    "20163"
                  ],
                  "boost": 1
                }
              },
              {
                "term": {
                  "shipMethod": {
                    "value": "TD_DLV",
                    "boost": 1
                  }
                }
              },
              {
                "term": {
                  "storeType": {
                    "value": "DS",
                    "boost": 1
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  }
}

search profiler

explain 결과값

{
  "_index" : "hyper-item_2023.05.09.14.57",
  "_type" : "_doc",
  "_id" : "1657301588000FA6F960FF6852F49090B7451CB85EC2E",
  "matched" : true,
  "explanation" : {
    "value" : 2000.0,
    "description" : "sum of:",
    "details" : [
      {
        "value" : 2000.0,
        "description" : "min of:",
        "details" : [
          {
            "value" : 2000.0,
            "description" : "function score, score mode [sum]",
            "details" : [
              {
                "value" : 0.0,
                "description" : "product of:",
                "details" : [
                  {
                    "value" : 1.0,
                    "description" : "constant score 1.0 - no function provided",
                    "details" : [ ]
                  },
                  {
                    "value" : 0.0,
                    "description" : "weight",
                    "details" : [ ]
                  }
                ]
              },
              {
                "value" : 1000.0,
                "description" : "script score function, computed with script:\"Script{type=inline, lang='boost_script', idOrCode='category_boost_df', options={}, params={operation_mode=+, operation_score=1000, field=category.cateCdGroup, category_id=200095, default_score=1000}}\"",
                "details" : [
                  {
                    "value" : 1.0,
                    "description" : "_score: ",
                    "details" : [
                      {
                        "value" : 1.0,
                        "description" : "max of:",
                        "details" : [
                          {
                            "value" : 1.0,
                            "description" : "(brandNmEng:스낵 | brandNmEng:스넥 | brandNmEng:쿠키 | brandNmEng:비스켓 | brandNmEng:비스킷 | brandNmEng:비스캣 | brandNmEng:프레첼 | brandNmEng:샌드 | brandNmEng:웨하스 | brandNmEng:과자 | brandNmKor:스낵 | brandNmKor:스넥 | brandNmKor:쿠키 | brandNmKor:비스켓 | brandNmKor:비스킷 | brandNmKor:비스캣 | brandNmKor:프레첼 | brandNmKor:샌드 | brandNmKor:웨하스 | brandNmKor:과자 | itemOptionNms:스낵 | itemOptionNms:스넥 | itemOptionNms:쿠키 | itemOptionNms:비스켓 | itemOptionNms:비스킷 | itemOptionNms:비스캣 | itemOptionNms:프레첼 | itemOptionNms:샌드 | itemOptionNms:웨하스 | itemOptionNms:과자 | promoKeyword:스낵 | promoKeyword:스넥 | promoKeyword:쿠키 | promoKeyword:비스켓 | promoKeyword:비스킷 | promoKeyword:비스캣 | promoKeyword:프레첼 | promoKeyword:샌드 | promoKeyword:웨하스 | promoKeyword:과자 | itemStoreInfo.eventInfo.eventKeyword:스낵 | itemStoreInfo.eventInfo.eventKeyword:스넥 | itemStoreInfo.eventInfo.eventKeyword:쿠키 | itemStoreInfo.eventInfo.eventKeyword:비스켓 | itemStoreInfo.eventInfo.eventKeyword:비스킷 | itemStoreInfo.eventInfo.eventKeyword:비스캣 | itemStoreInfo.eventInfo.eventKeyword:프레첼 | itemStoreInfo.eventInfo.eventKeyword:샌드 | itemStoreInfo.eventInfo.eventKeyword:웨하스 | itemStoreInfo.eventInfo.eventKeyword:과자 | searchKeyword:스낵 | searchKeyword:스넥 | searchKeyword:쿠키 | searchKeyword:비스켓 | searchKeyword:비스킷 | searchKeyword:비스캣 | searchKeyword:프레첼 | searchKeyword:샌드 | searchKeyword:웨하스 | searchKeyword:과자 | category.dcateNm:스낵 | category.dcateNm:스넥 | category.dcateNm:쿠키 | category.dcateNm:비스켓 | category.dcateNm:비스킷 | category.dcateNm:비스캣 | category.dcateNm:프레첼 | category.dcateNm:샌드 | category.dcateNm:웨하스 | category.dcateNm:과자 | searchItemNm:스낵 | searchItemNm:스넥 | searchItemNm:쿠키 | searchItemNm:비스켓 | searchItemNm:비스킷 | searchItemNm:비스캣 | searchItemNm:프레첼 | searchItemNm:샌드 | searchItemNm:웨하스 | searchItemNm:과자)",
                            "details" : [ ]
                          }
                        ]
                      }
                    ]
                  }
                ]
              },
              {
                "value" : 1000.0,
                "description" : "script score function, computed with script:\"Script{type=inline, lang='boost_script', idOrCode='category_boost_df', options={}, params={operation_mode=+, operation_score=1000, field=category.cateCdGroup, category_id=300633, default_score=1000}}\"",
                "details" : [
                  {
                    "value" : 1.0,
                    "description" : "_score: ",
                    "details" : [
                      {
                        "value" : 1.0,
                        "description" : "max of:",
                        "details" : [
                          {
                            "value" : 1.0,
                            "description" : "(brandNmEng:스낵 | brandNmEng:스넥 | brandNmEng:쿠키 | brandNmEng:비스켓 | brandNmEng:비스킷 | brandNmEng:비스캣 | brandNmEng:프레첼 | brandNmEng:샌드 | brandNmEng:웨하스 | brandNmEng:과자 | brandNmKor:스낵 | brandNmKor:스넥 | brandNmKor:쿠키 | brandNmKor:비스켓 | brandNmKor:비스킷 | brandNmKor:비스캣 | brandNmKor:프레첼 | brandNmKor:샌드 | brandNmKor:웨하스 | brandNmKor:과자 | itemOptionNms:스낵 | itemOptionNms:스넥 | itemOptionNms:쿠키 | itemOptionNms:비스켓 | itemOptionNms:비스킷 | itemOptionNms:비스캣 | itemOptionNms:프레첼 | itemOptionNms:샌드 | itemOptionNms:웨하스 | itemOptionNms:과자 | promoKeyword:스낵 | promoKeyword:스넥 | promoKeyword:쿠키 | promoKeyword:비스켓 | promoKeyword:비스킷 | promoKeyword:비스캣 | promoKeyword:프레첼 | promoKeyword:샌드 | promoKeyword:웨하스 | promoKeyword:과자 | itemStoreInfo.eventInfo.eventKeyword:스낵 | itemStoreInfo.eventInfo.eventKeyword:스넥 | itemStoreInfo.eventInfo.eventKeyword:쿠키 | itemStoreInfo.eventInfo.eventKeyword:비스켓 | itemStoreInfo.eventInfo.eventKeyword:비스킷 | itemStoreInfo.eventInfo.eventKeyword:비스캣 | itemStoreInfo.eventInfo.eventKeyword:프레첼 | itemStoreInfo.eventInfo.eventKeyword:샌드 | itemStoreInfo.eventInfo.eventKeyword:웨하스 | itemStoreInfo.eventInfo.eventKeyword:과자 | searchKeyword:스낵 | searchKeyword:스넥 | searchKeyword:쿠키 | searchKeyword:비스켓 | searchKeyword:비스킷 | searchKeyword:비스캣 | searchKeyword:프레첼 | searchKeyword:샌드 | searchKeyword:웨하스 | searchKeyword:과자 | category.dcateNm:스낵 | category.dcateNm:스넥 | category.dcateNm:쿠키 | category.dcateNm:비스켓 | category.dcateNm:비스킷 | category.dcateNm:비스캣 | category.dcateNm:프레첼 | category.dcateNm:샌드 | category.dcateNm:웨하스 | category.dcateNm:과자 | searchItemNm:스낵 | searchItemNm:스넥 | searchItemNm:쿠키 | searchItemNm:비스켓 | searchItemNm:비스킷 | searchItemNm:비스캣 | searchItemNm:프레첼 | searchItemNm:샌드 | searchItemNm:웨하스 | searchItemNm:과자)",
                            "details" : [ ]
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "value" : 3.4028235E38,
            "description" : "maxBoost",
            "details" : [ ]
          }
        ]
      },
      {
        "value" : 0.0,
        "description" : "match on required clause, product of:",
        "details" : [
          {
            "value" : 0.0,
            "description" : "# clause",
            "details" : [ ]
          },
          {
            "value" : 1.0,
            "description" : "saleStartDt:[-9223372036854775808 TO 1683622859999]",
            "details" : [ ]
          }
        ]
      },
      {
        "value" : 0.0,
        "description" : "match on required clause, product of:",
        "details" : [
          {
            "value" : 0.0,
            "description" : "# clause",
            "details" : [ ]
          },
          {
            "value" : 1.0,
            "description" : "DocValuesFieldExistsQuery [field=saleEndDt]",
            "details" : [ ]
          }
        ]
      },
      {
        "value" : 0.0,
        "description" : "match on required clause, product of:",
        "details" : [
          {
            "value" : 0.0,
            "description" : "# clause",
            "details" : [ ]
          },
          {
            "value" : 1.0,
            "description" : "(docDispYn:Y | rsvDocDispYn:Y)",
            "details" : [ ]
          }
        ]
      },
      {
        "value" : 0.0,
        "description" : "match on required clause, product of:",
        "details" : [
          {
            "value" : 0.0,
            "description" : "# clause",
            "details" : [ ]
          },
          {
            "value" : 1.0,
            "description" : "ConstantScore(itemStoreInfo.storeId:20163 itemStoreInfo.storeId:37) shipMethod:TD_DLV storeType:DS",
            "details" : [ ]
          }
        ]
      }
    ]
  }
}

 

GET hyper-item/_analyze
{
  "analyzer": "search_analyzer",
  "text": [
    "과자"
  ]
}

 

반응형