Search based on ID values in nested queries

Hi!

I have mapping that contains a title and note field, in addition to a links_to_asset field:

"links_to_asset": {
	"type": "nested",
	"properties": {
		"comment": {
			"type": "text",
			"fields": {
				"std": {
					"type": "text",
					"fields": {
						"std": {
							"type": "text",
							"analyzer": "standard"
						}
					},
					"analyzer": "asset_en_analyzer"
				}
			}
		},
		"creation": {
			"type": "date",
			"format": "date_hour_minute_second"
		},
		"from_asset": {
			"type": "integer"
		},
		"modification": {
			"type": "date",
			"format": "date_hour_minute_second"
		},
		"note_link_id": {
			"type": "long"
		},
		"to_asset": {
			"type": "integer"
		},
		"user_id": {
			"type": "long"
		}
	}
}

... where the from_asset and to_asset fields are equal to the _id field values in documents.

So far, I have:

{
    "query": {
        "nested": {
            "path": "links_to_asset",
            "query": {
                "bool": {
                    "must": {
                        "match": {
                            "links_to_asset.comment": "research suggests chaotic"
                        }
                    }
                }
            }
        }
    }
}

... which is working, but I'm struggling with a few things:

  1. is it possible to restrict the search to documents by their _id and user_id fields;
  2. and is it possible to search the title fields of the documents belonging to the from_asset and to_asset fields?

I've been experimenting but with no success (I'm unable to combine function_score with nested, as an example).

Based on an answer to a question on StackOverflow, I've had a partial success with:

{
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "user_id": 11
                    }
                },
                {
                    "term": {
                        "_id": 19976
                    }
                },
                {
                    "nested": {
                        "path": "links_to_asset",
                        "score_mode": "max",
                        "query": {
                            "bool": {
                                "must": {
                                    "match": {
                                        "links_to_asset.comment": "complex pattern resembles wave scientist"
                                    }
                                }
                            }
                        },
                        "inner_hits": {}
                    }
                }
            ]
        }
    }
}

... however, I still need to — somehow — use the _id value to retrieve the title from the document to which is relates.

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