How to translate an ElasticSearch multimatch search query from cURL into JAVA? -


so, having made (right) query in es , tested against local es installation using sense plugin, facing problem: how same code using es java api. here query trying translate:

{ "size": 5, "query": {   "multi_match": {      "query": "physics",      "type": "most_fields",      "fields": [          "document.title^10",          "document.title.shingles^2",          "document.title.ngrams",          "person.name^10",          "person.name.shingles^2",          "person.name.ngrams",          "document.topics.name^10",          "document.topics.name.shingles^2",          "document.topics.name.ngrams"       ],       "operator": "and"     }   } }' 

i know should this, not quite sure:

 node node = nodebuilder().client(true).node();     client client = node.client();      searchresponse response = client.preparesearch("dlsnew")             .settypes("person", "document")             .setsearchtype(searchtype.dfs_query_then_fetch)             .setquery(querybuilders.multimatchquery("physics",                     "document.title^10",                     "document.title.shingles^2",                     "document.title.ngrams",                     "person.name^10",                     "person.name.shingles^2",                     "person.name.ngrams",                     "document.topics.name^10",                     "document.topics.name.shingles^2",                     "document.topics.name.ngrams"))             .setfrom(0).setsize(5).setexplain(true)             .execute()             .actionget();      searchhit[] results = response.gethits().gethits(); 

also, how handle "operator" , "type":"most_fields" parts query?

you did it

querybuilders.multimatchquery("physics",                 "document.title^10",                 "document.title.shingles^2",                 "document.title.ngrams",                 "person.name^10",                 "person.name.shingles^2",                 "person.name.ngrams",                 "document.topics.name^10",                 "document.topics.name.shingles^2",                 "document.topics.name.ngrams")                 .operator(matchquerybuilder.operator.and)                 .type(multimatchquerybuilder.type.most_fields); 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -