elastic alias

개발새발·2021년 12월 12일
0

elasticsearch

목록 보기
8/54

회사에서 alias 처리된 필드에 대해 검색할 일이 생겼는데, 검색해보면서 나온 결과에 대해 공유해보려고 한다. 😐


👁️ 결과는?

  1. alias 한 필드명과 기존 필드명에 대해서 모두 검색이 가능하다.
  2. response로 나온 결과에는 alias한 필드명으로 나오지 않고, 기존 필드명으로 나온다. alias 한 필드명으로 노출시키기 위해서는 아래처럼 script_fields 옵션으로 가능하다. 단, 이 옵션 사용시 _source 결과로 나오는 게 아니라 fields 결과로 나온다.

사용 예시)

[검색시]

{
    "query": {
        "bool": {
            "must": [],
            "filter": []
        }
    },
    "sort": {
        "sale_count": "desc"
    },
    "from": 0,
    "size": 10,
    "script_fields": {
        "store_id": {
            "script": {
                "source": "if(params.containsKey('_source') && params._source.containsKey('mall_id')) return params._source['mall_id']"
            }
        }
    }
}

[검색결과]

{
  "total": {
    "value": 10000,
    "relation": "eq"
  },
  "max_score": null,
  "hits": [
    {
      "_index": "shop_1028",
      "_type": "_doc",
      "_id": "denazify76_34799",
      "_score": null,
      "_source": {
        "benefits": [
          {
            "end_date": 7900818868075233000,
            "discount_value_unit": "vitalized",
            "benefit_type": "prescribed",
            "purchase_start_price": 4813464560903481000,
            "benefit_sub_type": "gunnings",
            "benefit_no": "altering",
            "name": "owe",
            "discount_value": 1171772506332667000,
            "platform_types": "fricasseeing",
            "start_date": 6626725703279895000,
            "purchase_end_price": -1687283856519699500
          }
        ],
        "store_id": "denazify76",
        "shop_properties": [
          "masklike",
          "suppositions",
          "cheaper",
          "penster",
          "bumblebee"
        ],
        "shop_age": "20-30",
        "shop_region": "shove",
        "shop_language": "CHN",
        "shop_country": "KRW",
        "shop_grade": "PLATINUM",
        "shop_name": "zygotesdieback",
        "shop_sex": "FEMALE",
        "update_date": "2021-12-03T15:04:09.075+09:00",
        "shipping_fee_type": "T",
        "social_logins": [
          "discrepancies",
          "acrasin",
          "amortizable"
        ],
        "shop_url": "https://expertshoopoesswanherd.com",
        "logo": "https://foldedrelinegeneralissimos.com",
        "use_naverpay": true,
        "created_date": "2021-12-03T15:04:09.075+09:00",
        "shop_currency_code": "ENG",
        "shop_no": 34799
      },
      "fields": {
        "shop_no_string": [ // shop_no_string이 이렇게 나옴.
          "34799"
        ]
      },
      "sort": [
        "zygotesdieback"
      ]
    },
    {
      "_index": "shop_1028",
      "_type": "_doc",
      "_id": "spearers671_70131",
      "_score": null,
      "_source": {
        "benefits": [
          {
            "end_date": 2102441274131046400,
            "discount_value_unit": "upflowing",
            "benefit_type": "gleys",
            "purchase_start_price": 680946365587136900,
            "benefit_sub_type": "digestor",
            "benefit_no": "contemn",
            "name": "cofounders",
            "discount_value": -3064441479093757400,
            "platform_types": "politer",
            "start_date": 6311718923014730000,
            "purchase_end_price": -539203902821484860
          },
          {
            "end_date": 4338101522295821300,
            "discount_value_unit": "bethels",
            "benefit_type": "reman",
            "purchase_start_price": 8490761748890435000,
            "benefit_sub_type": "cornettists",
            "benefit_no": "cogitating",
            "name": "determined",
            "discount_value": -5325822830468841000,
            "platform_types": "thoughtfully",
            "start_date": 754139411766601500,
            "purchase_end_price": -4692555770248052000
          },
          {
            "end_date": 1315665645805642800,
            "discount_value_unit": "hissers",
            "benefit_type": "duo",
            "purchase_start_price": 3457794918191029000,
            "benefit_sub_type": "armoury",
            "benefit_no": "bilgiest",
            "name": "comprizing",
            "discount_value": -1013492827676637800,
            "platform_types": "bijous",
            "start_date": 8489088729597800000,
            "purchase_end_price": 7722080384887001000
          }
        ],
        "store_id": "spearers671",
        "shop_properties": [
          "felonies",
          "whelp",
          "rammed",
          "sparkish",
          "untread"
        ],
        "shop_age": "0-1",
        "shop_region": "displodes",
        "shop_language": "TWI",
        "shop_country": "TWI",
        "shop_grade": "SVIP",
        "shop_name": "zygomasweethearts",
        "shop_sex": "FEMALE",
        "update_date": "2021-12-03T15:04:09.774+09:00",
        "social_logins": [
          "destroyers",
          "parametrically",
          "visionless"
        ],
        "shop_url": "https://disjectingsequentialprefaced.com",
        "logo": "https://tegspulicidearbutuses.com",
        "use_naverpay": false,
        "created_date": "2021-12-03T15:04:09.774+09:00",
        "shop_currency_code": "CHN",
        "shop_no": 70131
      },
      "fields": {
        "shop_no_string": [ // shop_no_string이 이렇게 나옴.
          "70131"
        ]
      },
      "sort": [
        "zygomasweethearts"
      ]
    },
		....
	 ]
}
profile
발새발개

0개의 댓글