0

I am using Elastic 6.0 .My kibana query is as below

  "bool": {
       "must": [
          {
           "match": {
             "relationships.relation": {
               "query": "spouse"
            }
      }
    },
    {
      "match": {
        "relationships.first_name": {
          "query": "james"
        }
      }
    },
    {
      "match": {
        "relationships.last_name": {
          "query": "smith"
        }
      }
    }
  ]
}

which gives me results as

    1.    "relationships": [
        {
          "first_name": "John",
          "last_name": "Heafner",
          "relation": "Father"
        },
        {
          "first_name": "Mary",
          "last_name": "Dellinger",
          "relation": "Mother"
        },
        {
          "first_name": "James S.",
          "last_name": "Smith",
          "relation": "Spouse"
        }
      ]

    2. "relationships": [
        {
          "first_name": "James",
          "last_name": "Hickey",
          "relation": "Father"
        },
        {
          "first_name": "Mary",
          "last_name": "Raftery",
          "relation": "Mother"
        },
        {
          "first_name": "Richard",
          "last_name": "Smith",
          "relation": "Spouse"
        }
      ]

I want only 1st result as it contains exact match based on my query
{ "first_name": "James S.", "last_name": "Smith", "relation": "Spouse" } I have tried term query but it is giving same results as above. Any suggestion would be of much help.

1 Answer 1

1

This sounds like you have relationships mapped as an object type. For this to work as you expect, relationships needs to be mapped as a nested type and you should use nested queries to query fields of the nested objects.

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

2 Comments

Is there any other option as above solution means I need to change existing mapping
No other option I'm afraid. The easiest way to remedy may be to use the Reindex API to reindex documents into a new index that has the nested mapping for relationships configured.

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.