0
votes

I am using Elastic Search 6.5.4 and NEST client Version 6. I have an array of strings to be searched with a field in the index. I tried using Terms Query and it is as follows.

Example 

dynamicOrganizationList = [ "org1","org2" ]. 
And in my Index I have different organization values for different records. Like for Document 1, I have org1 as Organization.<b For 2nd document, I have org2 as an organization and for 3rd document  have org3 as organization

{
   {
       id:"doc1",
       Organization:"org1"
   }
   {
       id:"doc2",
       Organization:"org2"
   }
   {
       id:"doc3",
       Organization:"org3"
   }
}

Now I need the records having organization Ids as org1 or org2.

This is the query I have used

.Query(q => q.Terms(b => b.Name("metrics_query").Boost(1.1).Field(f => f.Organization).Terms(dynamicOrganizationList))

Thanks in advance.

1
Query looks fine. Is output empty?jaspreet chahal
@jaspreetchahal. Yes the output is empty. Can you please help me out.roopteja
same response @jaspreetchahalroopteja
are there spaces in your input terms?jaspreet chahal
yes @jaspreetchahalroopteja

1 Answers

1
votes

Term or terms query doesn't analyze input text i.e input text is not split in tokens using standard analyzer

ex "organization" field type text "organization":["a b c"] is stored as ["a","b","c"](3 separate tokens). So your query is trying to match "a b c" with either "a" or "b" or "c".

You need to do search on keyword field(text is stored as it is). By default all text field have a sub field named keyword of type "keyword".

Use .Field(f => f.Organization.Suffix("keyword")) instead of .Field(f => f.Organization)