How to write a search query to find values of multiple fields

I have 10 id's and I want particular field value from all id's to be displayed .I wrote the following query.It is displaying all the fields in the id's and when i try to sort out with fields names,it's showing error.Please could you help me with the same.Here is the code snippet that i have tried.

GET /classified_classified_load/predefineed/_search
{
"query": {
"ids" : {
"multi_match" : {
"values" : ["11", "22", "322"]
"fields": [ "ExecutionDate", "Executionyear" ]
}
}
}
}

The field list under multi-match specifies which fields to search, it does not limit which fields are returned in the search results which is what I believe you are trying to do. I just tried this on a sample index I have and it works:

{ 
  "fields": [ "document", "orgs.normalized" ],
  "query": {
    "multi_match" : {
      "query":    "GOP",
      "fields": [ "document", "orgs.normalized" ]
    }
  }
}

Note the field list outside of the query object, adding that gave the desired results. Without it, I too was seeing all fields in the response vice just those specified within the mutli_match object. Hope this helps.

Kevin

Hi kevin,
Thank you very much for replying back.but still the query is not working for me.Please let me know where I'am wrong in the following code snippet-where i want to find city field in particular document.
{
"fields": [ "document", "orgs.normalized" ],
"query": {
"multi_match" : {
"query": "City",
"fields": [ "document", "orgs.normalized" ]
}
}
}

Thank you in advance!!!

@ja_chan You need to replace the field names in the outer fields array with the field(s) that you want to return and replace the inner fields array with the fields that you want to search against. Below is a sample of how to only search the city field for the word Seattle and only return that field. The document and orgs.normalized field names in my original example were from my index, sorry for the confusion on that:

{
"fields": [ "city"],
"query": {
"multi_match" : {
"query": "Seattle",
"fields": [ "city" ]
}
}
}

One thing to note, if your city field is set to not_analyzed in your index mapping then you will need to make sure that the case, etc of your query term explicitly matches what is in your index. Please give the updated query above a try. Thanks.

Kevin

Hello Kevin,
Thank you for replying back and for your time and effort in helping me.I after trying this,it didn't work.May be I was wrong in communicating my problem.Let me brief you What I wanted.

Suppose there is a employee table.I wanted to know date of brith of all the few employees.How do we do it.

Let me write it down as sql query:

select date of birth,employee id from employee where employee id IN (2,3,4,5,22,45,64);

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.