일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- API
- MySQL
- licence delete curl
- analyzer test
- aggregation
- zip 파일 암호화
- ELASTIC
- Kafka
- plugin
- sort
- query
- high level client
- flask
- license delete
- Java
- TensorFlow
- 파이썬
- License
- springboot
- 차트
- aggs
- token filter test
- 900gle
- matplotlib
- Mac
- Elasticsearch
- zip 암호화
- Python
- docker
- Test
Archives
- Today
- Total
개발잡부
[900] Java High Level REST Client Query 본문
반응형
https://ldh-6019.tistory.com/201
여기서 작업한 쿼리를 High Level REST Client 로 변경해보자
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Vector<Double> vectors = TextEmbedding.getVector(
TextEmbeddingDTO.builder()
.tensorApiUrl("http://localhost:5000/vectors")
.keyword(searchWord).build()
);
String[] includeFields = new String[]{"name", "category"};
String[] excludeFields = new String[]{"feature_vector"};
searchSourceBuilder.fetchSource(includeFields, excludeFields);
Map<String, Object> map = new HashMap<>();
map.put("query_vector", vectors);
ScriptScoreQueryBuilder functionScoreQueryBuilder = new ScriptScoreQueryBuilder(
QueryBuilders.multiMatchQuery(searchWord, "name", "category"),
new Script(
Script.DEFAULT_SCRIPT_TYPE,
Script.DEFAULT_SCRIPT_LANG,
"cosineSimilarity(params.query_vector, 'feature_vector') * doc['weight'].value * doc['populr'].value / doc['name'].length + doc['category'].length", map)
);
searchSourceBuilder.query(
functionScoreQueryBuilder
);
searchSourceBuilder.size(8);
searchRequest.source(searchSourceBuilder);
{
"size":8,
"query":{
"script_score":{
"query":{
"multi_match":{
"query":"나이키",
"fields":[
"name, category^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.0
}
},
"script":{
"source":"cosineSimilarity(params.query_vector, 'feature_vector') * doc['weight'].value * doc['populr'].value / doc['name'].length + doc['category'].length",
"lang":"painless",
"params":{
"query_vector":[
8.812982123345137E-4,
0.026942647993564606,
-0.05886850133538246,
0.0026577573735266924,
-0.04516655206680298,
........
]
}
},
"boost":1.0
}
},
"_source":{
"includes":[
"name",
"category"
],
"excludes":[
"feature_vector"
]
}
}
와.. 씨.. 이거 안되네
템플릿으로 변경 해야것네
반응형
'900gle shopping > api' 카테고리의 다른 글
[900] Java High Level REST Client Query 3 (0) | 2022.01.27 |
---|---|
[900gle] Java High Level REST Client Query 2 (0) | 2022.01.26 |
[900gle] Search Template (0) | 2022.01.25 |
[900] Search API (0) | 2022.01.19 |
[900gle] Text embedding API (0) | 2022.01.19 |
Comments