Search in multi_field type


(Div Sriram Sriram) #1

Usecase: Typeahead search:
I have a question with Multi_field search, the property with type I have is:

content: {
       type: "string"
       fields: {
             raw: {
                     type: "string"
                     index: "not_analyzed"
                    }
      }
}

So as and when I type I must be able to fetch the results, now what is optimal way to search against content and content.raw field?

I was thinking of a query like this?

    "bool" : {
        "should" : [ 
    		"match" : { 
    			"content" : { "query" : "post", "operator" : "and" } 
   			}, 
    		"match" : { 
    			"content.raw" : { "query" : "postin", "operator" : "and" } 
    		}
    	]
}

(David Pilato) #2

Well, should should be an array of clauses.

So something like:

"bool" : {
        "should" : [ 
    		"match" : { 
    			"content" : { "query" : "post", "operator" : "and" } 
   			}, 
    		"match" : { 
    			"content.raw" : { "query" : "postin", "operator" : "and" } 
    		}
    	]
}

(Div Sriram Sriram) #3

Thanks @dadoonet My concern is the query itself. Not the syntax.
I am in the analysis phase. So it would be very helpful if u can help me with the optimal query for the problem.
I have edited my syntax based on your comments. Many Thanks!!!


(David Pilato) #4

So yes, IMO the way you write the query is correct.


(Div Sriram Sriram) #5

Thank You :smile:


(system) #7