Searching with multiple values - JAVA


(issam) #1

Hello,

I have to search on the indexes already created with multiple values in a given field, but I always get nothing in the result

Can you tell please if it is ok with the following code (I use elasticsearch Java API)

  • query = QueryBuilders.termsQuery(param, values);
  • boolQueryBuilder.must(query);

I have something like that in boolQueryBuilder

  • {
  • "bool" : {
  • "must" : [ {
    
  •   "terms" : {
    
  •     "param1" : [ value1, value2, value3 ]
    
  •   }
    
  • }, {
    
  •   "wildcard" : {
    
  •     "param2" : "*"
    
  •   }
    
  • } ]
    

I'm sure, that value1, 2 & 3 already exist, but I always get nothing, is there anyone who has an idea please ?

Thank you


(issam) #2

well, that was quickly, it is ok with using the termsQuery search with many values in one a single field, the problem here, is that my values contain "-" wich is a special character, so elasticsearch replace it with space (I think)

If any one has an answer, for this problem (special characters) I'll be really thankful


(Christoph) #3

Take a look at the different Tokenizers, the default is the Standard tokenizer which splits on some characters (as you have seen). Maybe start with the Whitespace tokenizer instead.


(issam) #4

Thank you for Christoph, I found how to modify the tokenizer to whistespace one (using JAVA) but now, the wildcard terms are not working anymore, '*' and '?' are not considered token chars anymore, which is not good because I need these characters in my search

Is there anyway to keep '*' and '?' and remove only other characters such as '-' and '@' from token chars ??

Thank you


(Christoph) #5

I'm afraid I'm not sure I understand what you are trying to do here. This wildcard query basically matches everything in the param2 field. Also I don't quiet understand what you mean by "'*' and '?' are not considered token chars anymore". Maybe you can give an example of a document you are trying to find and which isn't returned by the query you are using?


(system) #6