I have the following requirements
a) Show suggestions if a query has hits in both query_terms and trigger_terms
b) Show suggestions if a query has hits in query_terms and trigger_terms is an empty array with no content
Here is my mapping
{
"mappings": {
"concepts": {
"properties": {
"query_terms": {
"type": "keyword"
},
"trigger_terms": {
"type": "keyword"
},
"suggestions": {
"type": "keyword"
}
}
}
}
}
Here is the sample data
Document 1:
_source
{
"query_terms" : [
"audit",
"audits"
"audited"
],
"trigger_terms" : [
"audit",
"return"
],
"suggestions" : '[
"examination",
"inspection",
"investigation"
]
}
Document 2:
_source
{
"query_terms" : [
"next",
"test"
"audited"
],
"trigger_terms" : [
"next",
"return",
"test"
],
"suggestions" : '[
"same offense",
"same evidence",
"investigation"
]
}
Document 3:
_source
{
"query_terms" : [
"best",
"fit"
"perfect",
"audit"
],
"trigger_terms" : [ ],
"suggestions" : '[
"double jeopardy",
"same elements",
"same evidence"
]
}
And my query
{
"query": {
"bool": {
"must": [
{
"terms":
{
"query_terms": ["audit"]
}
},
{
"terms":
{
"trigger_terms": ["audit"]
}
}
]
}
}
}
when I execute the query against Elasticsearch 5.2, I expect to see Document1 ( since audit has hits in both query_terms and trigger_terms ) and Document3 ( since audit has hits in query_terms and trigger_terms is an empty array) but I only see Document1
I modified the query but that doesn't work either
{
"query": {
"bool": {
"must": [
{
"terms":
{
"query_terms": ["audit"]
}
},
{
"terms":
{
"trigger_terms": ["audit"]
}
},
{
"exists" :
{
"field" : "trigger_terms"
}
}
]
}
}
}
could someone please help?