I basically would like to search for a query with 2 filters/tags
(e.g. 1 city in 2 countries - US OR CANADA)
ElasticSearchAPi.java
public interface ElasticSearchAPI {
@GET("_search/")
Call search(
@HeaderMap Map headers,
@Query("default_operator") String operator,
@Query("q") String query
);
}
Part of Search.java
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
ElasticSearchAPI searchAPI = retrofit.create(ElasticSearchAPI.class);
HashMap headerMap = new HashMap();
headerMap.put("Authorization", Credentials.basic("user", mElasticSearchPassword));
String searchString = "";
if(!mSearchText.equals("")){
searchString = searchString + mSearchText.getText().toString() + "*";
}
if(!mPrefCountry.equals("")){
searchString = searchString + " country:" + mPrefCountry;
}
Call call = searchAPI.search(headerMap, "AND", searchString);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
HitsList hitsList = new HitsList();
String jsonResponse = "";
try{
Log.d(TAG, "onResponse: server response: " + response.toString());
if(response.isSuccessful()){
hitsList = response.body().getHits();
}else{
jsonResponse = response.errorBody().string();
}
Log.d(TAG, "onResponse: hits: " + hitsList);
for(int i = 0; i call, Throwable t) {
Log.e(TAG, "onFailure: " + t.getMessage() );
Toast.makeText(getActivity(), "search failed", Toast.LENGTH_SHORT).show();
}
});
}
return false;
}
e.g. the code renders the ff query which shows the available cities with NEW in its name inside the country US :
_search?default_operator=AND&q=new*+country:Us
but what im trying to achieve is something like this :
_search?default_operator=AND&q=new*+country:Us||Canada
that should result in showing all cities with NEW in its name inside US OR CANADA.
but || doesnt seem to work, so im asking for the correct Retrofit OR operator, or something that can help me achieve my goal.