@monti.mauro Unfortunately, with couchbase there’s no direct query that offers merging contents from multiple fields and searching from the resultant data as if they belonged to a single field.
However there is a way this can be achieved by an index definition change, here’s how with an example -
Let’s say you have the 3 fields (from the example in the elastic documentation) whose results you want to combine …
- “title”
- “abstract”
- “body”
Here’s what you’ll need to do while defining the index:
- you will have the option to enter a
searchable as
for each of these fields.
- For your current use case, you can set the
searchable as
for all 3 fields to a common name:
title
will be searchable as fieldGroup
abstract
will be searchable as fieldGroup
body
will be searchable as fieldGroup
Your index mapping would then look like …
...
"default_mapping": {
"default_analyzer": "standard",
"dynamic": false,
"enabled": true,
"properties": {
"title": {
"dynamic": false,
"enabled": true,
"fields": [
{
"index": true,
"name": "fieldGroup",
"store": true,
"type": "text"
}
]
},
"abstract": {
"dynamic": false,
"enabled": true,
"fields": [
{
"index": true,
"name": "fieldGroup",
"store": true,
"type": "text"
}
]
},
"body": {
"dynamic": false,
"enabled": true,
"fields": [
{
"index": true,
"name": "fieldGroup",
"store": true,
"type": "text"
}
]
}
}
}
...
Now you search request would simply be …
{
"query": {
"match": "database systems",
"field": "fieldGroup",
"operator": "and"
}
}
Hope this works for you.