Hi friends am new on elasticsearch. I want to know if I can exclude certain fields from search from elastic search. To eloborate I want to ignore it from my search. It should not search that field when we specify but should be searchable on all the fields other then thats blacklisted.
In the below data i want to search for Product ABC in all other fields other then Service_Sold.Product_Name. I cam across excludes and whitelisting methods which is not feasible as we have lots of fields in index and would increase the complexity of the query.
Would appreciate any suggestions and help.
Note 7.10 version elastic-seach running queries on KIBANA
Here is the sample search query data.
{
"_index" : "_dev",
"_type" : "_doc",
"_id" : "data-2",
"_score" : 1.0,
"_source" : {
"type" : "datas",
"id_number" : 736762732784934,
"company_group_name" : "Customer ABC name 2",
"company_group_id" : 2,
"document_title" : "Product ABC title_736762732784934",
"effective_date" : "2011-01-26",
"Service_Sold" : [
{
"Type" : "Type XYZ",
"Product_Name" : "Product ABC"
}
]
}
}
CodePudding user response:
Try this
GET {YOUR_INDEX_NAME}/_search
{
"query": {
"bool": {
"must": [
{
"simple_query_string": {
"query": "Product ABC"
}
}
],
"must_not": [
{
"match_phrase": {
"Service_Sold.Product_Name": "Product ABC"
}
}
]
}
}
}
In your mapping the fields Service_Sold
must be nested
https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html
CodePudding user response:
{
"_index" : "_dev",
"_type" : "_doc",
"_id" : "data-2",
"_score" : 1.0,
"_source" : {
"type" : "datas",
"id_number" : 736762732784934,
"company_group_name" : "Customer ABC name 2",
"company_group_id" : 2,
"document_title" : "Product ABC title_736762732784934",
"effective_date" : "2011-01-26",
"Service_Sold" : [
{
"Type" : "Type XYZ",
"Product_Name" : "Product ABC",
"Product_Description" : "Product ABC"
}
]
}
}