Hello!
I have index with documents which have dynamic set of fields:
{
....
'company_id': 'xxxxxxxxxxxxxxxxxxxxxxx',
'fields': [
{
'name': 'first_name', 'value': ['First']
},
{
'name': 'last_name', 'value': ['Last']},
{
'name': 'phone', 'value': ['+000000000']
}
],
...
}
I need to handle 2 kinds of search requests.
Search only for documents which have specific field ('email' for
example) and ignore other.
Search for documents specific fields of which should match search
criteria (for example display only documents which fields with names
'first_name', 'last_name' or 'email' starts from 'a')
For first type of search request I'm create the following search query:
Hello!
I have index with documents which have dynamic set of fields:
{
....
'company_id': 'xxxxxxxxxxxxxxxxxxxxxxx',
'fields': [
{
'name': 'first_name', 'value': ['First']
},
{
'name': 'last_name', 'value': ['Last']},
{
'name': 'phone', 'value': ['+000000000']
}
],
...
}
I need to handle 2 kinds of search requests.
Search only for documents which have specific field ('email' for
example) and ignore other.
Search for documents specific fields of which should match search
criteria (for example display only documents which fields with names
'first_name', 'last_name' or 'email' starts from 'a')
For first type of search request I'm create the following search query:
The way queries on multi fields works is not by actually returning only
the documents where both fields exists, but think of it as a each one
reduces the documents to search on, and each one works against the whole
document. So, in your case, the filter does filter only for documents that
have email in the "fields.name", but then the prefix query will match on any fields.value that starts with f.
I think that a better solution for this is to move the "fields.name" to
be fields level document fields, for example:
Hello!
I have index with documents which have dynamic set of fields:
{
....
'company_id': 'xxxxxxxxxxxxxxxxxxxxxxx',
'fields': [
{
'name': 'first_name', 'value': ['First']
},
{
'name': 'last_name', 'value': ['Last']},
{
'name': 'phone', 'value': ['+000000000']
}
],
...
}
I need to handle 2 kinds of search requests.
Search only for documents which have specific field ('email' for
example) and ignore other.
Search for documents specific fields of which should match search
criteria (for example display only documents which fields with names
'first_name', 'last_name' or 'email' starts from 'a')
For first type of search request I'm create the following search query:
Hi,
The way queries on multi fields works is not by actually returning only
the documents where both fields exists, but think of it as a each one
reduces the documents to search on, and each one works against the whole
document. So, in your case, the filter does filter only for documents that
have email in the "fields.name", but then the prefix query will match on any fields.value that starts with f.
I think that a better solution for this is to move the "fields.name" to
be fields level document fields, for example:
{
"company_id" : "xxxx",
"first_name" : "first",
"last_name" : "last",
"phone" : "..."
}
Thank you, but for some purposes I have leave fields in structure of
my document but convert it to be an object:
{
"company_id": "xxxx",
"fields" {
"phone": [ "ddddd", "bbbbbb" ],
"first_name": [ "first" ],
"last_name": [ "last" ]
}
}
Now regular queries worked as expected but not more_like_this queries
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.