Hello, I'm afraid the question has already been asked before, but I could not find exactly the answer.
I'm indexing documents with this mapping:
id
title
content
product
category
I would like to do a query with :
filter on
product in ('prodA','prodB') and category in ('catA', 'catB')
query on
content : 'interesting text to find'
I've seen that I need a query and a filter, but can't find how to use both in the same search. Could someone clarify me that ?
Thanks
Frédéric
dadoonet
(David Pilato)
February 19, 2016, 4:59pm
2
Use a Bool query. It has a must clause and a filter clause.
Hi David,
thanks. I've tried this query
{
"query":{
"bool" : {
"must" : {
"term" : { "content" : "latitude" }
},
"filter": [{
"terms" : { "product" : ["prodA";"prodB" ]},
"terms" : { "categories" : ["guide" ]}
}]
}
}
}
What I expect is to have a query more or less like :
select * from type
where categories in ('guide') and product in ("prodA","prodB") and content
like %latitude%
It seems I'm wrong somewhere as I get results where product are equal to
prodC.
Any advice where I'm wrong ?
Thanks
Frédéric
dadoonet
(David Pilato)
February 22, 2016, 4:43pm
4
Be careful with your analyzers. They will play a big role here.
For example, if you could reproduce with a full SENSE script that would be easier to help you fixing your problem.
For example, prodA
might have been indexed as prodb
. So the Term query you use won't match.
About the content part, are you looking for full terms or do you also want to search for %atitu%
?
Hi,
prodA was an example, product names are more different. I'll check for
analyzers. For content, it is more a full text search %latitude%.
What do you mean by SENSE ?
Thanks
Frédéric
dadoonet
(David Pilato)
February 22, 2016, 9:54pm
6
Frederic_Houbie:
Hi,
prodA was an example, product names are more different. I'll check for
analyzers. For content, it is more a full text search %latitude%.
I guessed so. But still you can have issues with analyzers here.
Also look at: https://www.elastic.co/help/
David,
thanks,
I've installed Sense, nice apps. I've created a manual mapping with no
analyzers for the fields I want to filter on. Then, I've tries to create a
query. I'm there :
GET _search
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "decoding aixm metadata",
"fields": [
"title^3",
"content"
]
}
},
"filter": [
{
"terms": {
"categories": [
"Guide",
"API"
]
}
}
]
}
}
}
My question is now, where should I add a second filter on another field ?
Thanks
Frédéric
dadoonet
(David Pilato)
February 29, 2016, 2:33am
8
filter is an array. Add a new filter in it.