"caused_by": { "type": "illegal_argument_exception", "reason": "function reference [this::lambda$synthetic$0/3] matching [java.util.function.BiPredicate, test/2] not found due to an incorrect number of arguments" }

개발새발·2022년 8월 6일
0

elasticsearch

목록 보기
32/54

elasticsearch 계속하다 조회만 하다보니 이젠 막 헷갈린다.. 뭐가 뭐였는지 ㅠㅠ 이번에는 하다가 제목과 같은 에러가 났다. 그래서 원인찾기 돌입..!

원인 👩‍🍳

아래와 유사하게 코드를 짰는데, "caused_by": {"type": "illegal_argument_exception","reason": "function reference [this::lambda$synthetic$0/3] matching [java.util.function.BiPredicate, test/2] not found due to an incorrect number of arguments"} 이 에러가 자꾸 나는 것이 아닌가…ㅠㅠ 자세히 살펴보니 findAll 에서 문제가 생기는 것 같았다. 그런데, 이전에 비슷한 코드를 짰을 때는 문제가 없었는데 뭐지했는데…원인은 데이터에 있었다 🤓

POST {index}/_update_by_query

{
  "script": {
    "source": "def targets = ctx._source.nestedtypefields.findAll(nestedtypefield -> nestedtypefield.field == params.search_field);",
    "lang": "painless",
    "params": {
        "search_field": "test"
    }
  },
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "nestedtypefields",
            "query": {
              "term": {
                "nestedtypefields.field": "test"
              }
            }
          }
        }
      ]
    }
  }
}

해결 🍲

이전에 잘 됐던 데이터 (*response에서 hits만 떼왔다)

"hits": [
   {
		   "_index": "test",
       "_type": "_doc",
       "_id": "BAd9YoIB18RgfuY2YrXs",
       "_score": 3.1484344,
       "_source": {
           "nestedtypefield": [
              {
		             "field": "test1, test2, test3"
							}
           ]
       }
   }
]

현재 안되는 데이터 (*response에서 hits만 떼왔다)

"hits": [
   {
		   "_index": "test",
       "_type": "_doc",
       "_id": "BAd9YoIB18RgfuY2YrXs",
       "_score": 3.1484344,
       "_source": {
           "nestedtypefield": {
               "field": "test1, test2, test3"
           }
       }
   }
]

둘의 차이를 바로 알 수 있나요..? ㅎㅎ.. 안됐던 거는 nestedtypefield가 … array형태가 아니라서 findAll를 사용할 수 없는 경우였던 것이다. ㅜㅜ 휴.. 다시 한번 느꼈다… 섬세히 보자..

profile
발새발개

0개의 댓글