Created
July 21, 2011 05:11
-
-
Save nachiketkb/1096535 to your computer and use it in GitHub Desktop.
CustomScoreQueryBuilder.class working strangely.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mypackage; | |
import org.elasticsearch.index.query.xcontent.BoolQueryBuilder; | |
import org.elasticsearch.index.query.xcontent.CustomScoreQueryBuilder; | |
import org.elasticsearch.index.query.xcontent.QueryBuilders; | |
public class Tryout { | |
public static void main(String args[]) throws UnknownHostException, MongoException | |
{ | |
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); | |
boolQueryBuilder.boost(0); | |
boolQueryBuilder.must( QueryBuilders.boostingQuery().positive( QueryBuilders.termQuery("a1", "b1") ).negative( QueryBuilders.termQuery("c1", "d1") ).negativeBoost(0) ); | |
boolQueryBuilder.must( QueryBuilders.boostingQuery().positive( QueryBuilders.termQuery("a2", "b2") ).negative( QueryBuilders.termQuery("c2", "d2") ).negativeBoost(1) ); | |
CustomScoreQueryBuilder customScoreQueryBuilder = QueryBuilders.customScoreQuery( boolQueryBuilder ).script("scoring"); | |
customScoreQueryBuilder.lang("native"); | |
customScoreQueryBuilder.params(null); | |
System.out.println( customScoreQueryBuilder.buildAsUnsafeBytes() ); | |
} | |
} | |
Output of the code is | |
{ | |
"custom_score": | |
{ | |
"query": | |
{ | |
"bool": | |
{ | |
"must": | |
{ | |
"boosting": | |
{ | |
"positive": | |
{ | |
"term": | |
{ | |
"a1":"b1" | |
} | |
}, | |
"negative": | |
{ | |
"term": | |
{ | |
"c1":"d1" | |
} | |
}, | |
"negative_boost":0.0 | |
}, | |
"must": | |
{ | |
"boosting": | |
{ | |
"positive": | |
{ | |
"term": | |
{ | |
"a2":"b2" | |
} | |
}, | |
"negative": | |
{ | |
"term": | |
{ | |
"c2":"d2" | |
} | |
}, | |
"negative_boost":1.0 | |
}, | |
"boost":0.0 | |
} | |
}, | |
"script":"scoring", | |
"lang":"native" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment