0

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.

5
  • Query looks fine. Is output empty? Commented May 26, 2020 at 13:42
  • @jaspreetchahal. Yes the output is empty. Can you please help me out. Commented May 26, 2020 at 14:03
  • same response @jaspreetchahal Commented May 26, 2020 at 14:12
  • are there spaces in your input terms? Commented May 26, 2020 at 14:13
  • yes @jaspreetchahal Commented May 26, 2020 at 14:14

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @jaspreet chahal. It worked for me. I didnot add keyword suffix.
@roopteja glad could be of help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.