Query with Bool Must and Contain String


(Flavio Tom) #1

How can I create a JSON that returns the results in this type of condition?

User_ID = 1234 
AND Type_Search IN ('ALL', 'RESTRICT') 
AND (
title contains 'example string' 
OR 
content contains 'example string'
)

I create this JSON, but i don't know how search the string columns and this example don't return data:

{
"query": {
    "bool": {
        "must":
            [
                {
                    "term": {
                        "user_id": 14492
                    }
                },
                {
                    "terms": {
                        "type_search": [
                            "ALL",
                            "RESTRICT"
                        ]
                    }
                },
                {
                    "match": {
                        "title": "Modes"
                    }
                },
                {
                    "match": {
                        "content": "Modes"
                    }
                }
            ]
        }
    }
}

(Flavio Tom) #2

Problem solved.
Change the type of title and content to text, instead keyword.

Alter the JSON to:

{
"query": {
    "bool": {
        "must":
            [
                {
                    "term": {
                        "user_id": 14492
                    }
                },
                {
                    "terms": {
                        "type_search": [
                            "ALL",
                            "RESTRICT"
                        ]
                    }
                },{
			"query_string" : {
			       "fields" : ["title", "content"],
				"query" : "modes"
				}
			}
                }
}

(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.