Nested doc match only one doc and query term

Slight background:
ES version: 5.5,
Use case: a part will have a list of attributes and each attribute as the mapping below shows has name/value combo.

Mapping:

{
  "parts": {
    "mappings": {
      "basic": {
        "properties": {
          "attributes": {
            "type": "nested",
            "properties": {
              "name": {
                "type": "text"
              },
              "value": {
                "type": "text"
              }
            }
          },
          "description": {
            "type": "text"
          },
          "partNumber": {
            "type": "text"
          },
          "subCommodity": {
            "properties": {
              "name": {
                "type": "text"
              }
            }
          }
        }
      }
    }
  }
}

I am trying to query like so:

{
  "query": {
    "nested" : {
      "query" : {
        "match" : {
          "attributes.value" : {
            "query" : "red helmet"
          }
        }
      },
      "path" : "attributes",
      "score_mode" : "avg"
    }
  }
}

When I run that against a doc,

{
  "partNumber": "ABDEF-123456",
  "attributes": [
    {
      "name": "Color/Finish",
      "value": "Red"
    },
    {
      "name": "Type",
      "value": "Helmet"
    }
  ],
  "subCommodity": {
    "name": "Offroad Full Face 1/pc Adult Helmet"
  }
}

The _explain shows that "red" does not match but "helmet" does:

{
    "explanation": {
        "value": 6.135972,
        "description": "sum of:",
        "details": [
    ..
            "description": "weight(attributes.value:helmet in 260803) [PerFieldSimilarity], result of:",
        ]
    }
}

now when I query the non-nested field, subCommodity.name, on multiple query terms like so:

{
  "query": {
    "match": {
      "subCommodity.name": "Offroad Helmet"
    }
  }
}

The resulting explain indicates that both "offroad" and "helmet" match:

{
    "explanation": {
        "value": 4.0912876,
        "description": "sum of:",
        "details": [
            {
                "value": 4.0912876,
                "description": "sum of:",
                "details": [
                    {
                        "description": "weight(subCommodity.name:offroad in 260814) [PerFieldSimilarity], result of:",
                    },
                    {
                        "description": "weight(subCommodity.name:helmet in 260814) [PerFieldSimilarity], result of:",
                    }
                ]
            }
    ..
}

As a final example when I modify the single match on "red helmet" into a match per word like so,

{
  "query": {
    "bool": {
      "must": [{
        "nested" : {
          "query" : {
            "match" : {
              "attributes.value" : {
                "query" : "red"
              }
            }
          },
          "path" : "attributes",
          "score_mode" : "avg"
        }
      },{
        "nested" : {
          "query" : {
            "match" : {
              "attributes.value": {
                "query" : "helmet"
              }
            }
          },
          "path" : "attributes",
          "score_mode" : "avg"
        }
      }]
    }
  }
}

And run an explain against the example doc, both "red" and "helmet" match on attributes.value:

"description": "weight(attributes.value:red in 260810) [PerFieldSimilarity], result of:",
..
"description": "weight(attributes.value:helmet in 260803) [PerFieldSimilarity], result of:",

Now we can see both "red" and "helmet" matcn a nested doc at the path, attributes.value, in this query.

Does a nested doc query regardless of score mode only consider or report a single nested doc?

When I change the score modes in the explain the scores do not change so I do not believe more
than one nested doc is involved ie. once ES query phase finds an attribute matching "helmet" it
skips the remaining query terms notably "red".

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