0

I am trying to hit a query string on a nested field abc.answer which does not use any analyzer. Here is the query I am using:

   {
  "query": {
      "nested":{
           "path": "abc",
           "query":{
    "query_string": {
      "query": "photo AND delhi",
      "fields": ["answer"]



    }
    },
     "inner_hits": {
          "explain": true
      }

  }
  },
  "explain" : true,
  "sort" : [ {
    "_score" : { }
  } ]
}

I want to search for the document which has both dtp operator and bangalore in the nested field abc. But it is not showing any results.

My nested field structure :

"abc": [
            {
              "updatedAt": 1452073190000,
              "questionId": 1,
              "labelOriginal": "name",
              "createdAt": 1452073190000,
              "answerOriginal": "wexe",
              "answer": "wexe",
              "answerId": 0,
              "label": "name",
              "question": "what is your name?"
            },
            {
              "updatedAt": 1452073190000,
              "questionId": 2,
              "labelOriginal": "mobile",
              "createdAt": 1452073190000,
              "answerOriginal": "9000000000",
              "answer": "9000000000",
              "answerId": 0,
              "label": "mobile",
              "question": "What is your mobile number?"
            },
            {
              "updatedAt": 1452073190000,
              "questionId": 3,
              "labelOriginal": "email id",
              "createdAt": 1452073190000,
              "answerOriginal": "[email protected]",
              "answer": "[email protected]",
              "answerId": 0,
              "label": "email Id",
              "question": "What is your e-mail id ?"
            },
            {
              "updatedAt": 1452073190000,
              "questionId": 4,
              "labelOriginal": "current role",
              "createdAt": 1452073190000,
              "answerOriginal": "dtp operator",
              "answer": "DTP Operator",
              "answerId": 597,
              "label": "current role",
              "question": "What is your current role?"
            },
            {
              "updatedAt": 1452073190000,
              "questionId": 5,
              "labelOriginal": "city",
              "createdAt": 1452073190000,
              "answerOriginal": "bangalore",
              "answer": "Bangalore",
              "answerId": 23,
              "label": "city",
              "question": "Which city do you live in ?"
            },
            {
              "updatedAt": 1452073190000,
              "questionId": 6,
              "labelOriginal": "locality",
              "createdAt": 1452073190000,
              "answerOriginal": "80 ft. road",
              "answer": "80 Ft. Road",
              "answerId": 0,
              "label": "locality",
              "question": "Which locality do you live in ?"
            },
            {
              "updatedAt": 1452073190000,
              "questionId": 13,
              "labelOriginal": "job type",
              "createdAt": 1452073190000,
              "answerOriginal": "part time jobs",
              "answer": "Part Time Jobs",
              "answerId": 64,
              "label": "Job Type",
              "question": "Are you comfortable with working Full Time or Part Time?"
            },
            {
              "labelOriginal": "userDesiredCity",
              "answerOriginal": "bangalore",
              "answer": "Bangalore",
              "answerId": 23,
              "label": "userDesiredCity"
            }

1 Answer 1

1

You don't need a nested functionality for this kind of query, but the flat structure of a simple array.

Make your rsa field to have include_in_parent: true:

    "rsa": {
      "type": "nested",
      "include_in_parent": true, 
      "properties": {

Re-index the test documents and then use a query like this one (no nested query):

  "query": {
    "query_string": {
      "query": "dtp operator AND bangalore",
      "fields": [
        "rsa.answer"
      ]
    }
  }
Sign up to request clarification or add additional context in comments.

1 Comment

If I cannot change the mapping, can't I do this with existing mapping? If not the same query then something similar for the results I am expecting. Thanks

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.