다음 script_fields 스크립트를 사용하여 할 수있는 다른 방법도 있습니다 :
curl 'http://localhost:9200/test-idx/_search?pretty=true' -d '{
"query" : {
"match_all" : { }
},
"script_fields": {
"terms" : {
"script": "doc[field].values",
"params": {
"field": "message"
}
}
}
}'
는이 스크립트가 색인 된 실제 조건을 반환하면서, 또한 모든 필드 값을 캐시 및 대형에 유의하는 것이 중요합니다 인덱스는 많은 메모리를 사용할 수 있습니다.
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import java.io.StringReader;
// Cache analyzer for further use
cachedAnalyzer=(isdef cachedAnalyzer)?cachedAnalyzer:doc.mapperService().documentMapper(doc._type.value).mappers().indexAnalyzer();
terms=[];
// Get value from Fields Lookup
//val=_fields[field].values;
// Get value from Source Lookup
val=_source[field];
if(val != null) {
tokenStream=cachedAnalyzer.tokenStream(field, new StringReader(val));
CharTermAttribute termAttribute = tokenStream.addAttribute(CharTermAttribute);
while(tokenStream.incrementToken()) {
terms.add(termAttribute.toString())
};
tokenStream.close();
}
terms
이 MVEL 스크립트 config/scripts/analyze.mvel
로 저장하고 사용할 수 있습니다 : 그래서, 대형 인덱스에, 저장 필드 또는 소스에서 필드 값을 검색하고 다음 MVEL 스크립트를 사용하여 즉시 다시 재분석하는 것이 더 유용 할 수 있습니다 다음 검색어와 함께 :
curl 'http://localhost:9200/test-idx/_search?pretty=true' -d '{
"query" : {
"match_all" : { }
},
"script_fields": {
"terms" : {
"script": "analyze",
"params": {
"field": "message"
}
}
}
}'
이것은 무서운 !!! 좋은 대답! – javanna
그것은 무섭지만 재미 있습니다. :) DocLookup에서 IndexReader에 액세스 할 수 있었으면 좋겠다. (거기에 있지만, 지금은 비공개이다.) 그런 다음 두 번째 텍스트를 다시 분석하는 대신 용어 벡터를 사용할 수있었습니다. – imotov
네, 물론입니다. 스크립트없이 단어 벡터를 읽는 것도 좋을까요, 아니면 플러그인을 통해서 읽는 것이 좋을까요? – javanna