My JSON is like
{
"myData": [
{
"id": "4rr9a74a-d7cc-11e8-824f-0242ac160002",
"uri": "http://google.com/fagdge",
"statement": "Distinguish between random and non-random sampling methods, identify possible sources of bias in sampling, describe how such bias can be controlled and reduced, evaluate the characteristics of a good survey and well-designed experiment, design simple experiments or investigations to collect data to answer questions of interest, and make inferences from sample results.",
"dateTime": "2021-06-17T18:41:58+00:00",
"type": "Standard",
"hcs": "AII.DSP.1",
"docUri": {
"id": "c339d471-d7cb-11e8-824f-0242ac160002",
"uri": "https://api.test.com/24124",
"title": "Test Title"
},
"edLevels": ["09", "10", "11", "12"],
"itemUri": {
"title": "Test Title 1",
"identifier": "3397fbd1-7ad2-4236-bd5c-68b77f67b144",
"uri": "https://api.test.com/231221"
}
},
{
"id": "4tt9a74a-d7cc-11e8-824f-0243ac160002",
"uri": "http://google.com/fagdge",
"statement": "sources of bias in sampling, describe how such bias can be controlled and reduced, evaluate the characteristics of a good survey and well-designed experiment, design simple experiments or investigations to collect data to answer questions of interest, and make inferences from sample results.",
"dateTime": "2021-06-17T18:41:58+00:00",
"type": "Standard",
"hcs": "AII.DSP.2",
"docUri": {
"id": "c559d471-d7cb-11e8-824f-0242ac160002",
"uri": "https://api.test.com/24124",
"title": "Test Title 22"
},
"edLevels": ["09", "10", "11", "12"],
"itemUri": {
"title": "Test Title 2",
"identifier": "6697fbd1-7ad2-4236-bd5c-68b77f67b144",
"uri": "https://api.test.com/231221"
}
}
]
}
and I want to search hcs and matched value in elastic search using php and laravel?
I have tried below code:
$client = ClientBuilder::create()
->setHosts(['http://127.0.0.1:9200'])
->setBasicAuthentication('<user>', '<pass>')
->build();
try {
$params = [
'body' => [
'query' => [
'nested' => [
"path" => "myData",
"query" => [
'match' => [
'myData.hcs' => 'AII.DSP.1'
]
]
]
]
]
];
$response = $client->search($params);
dd($response);
} catch (NoNodesAvailableException $e) {
printf ("NoNodesAvailableException: %s\n", $e->getMessage());
}
exit;
But getting below error
failed to create query: [nested] nested object under path
Edit:
Mapping is:
{
"myData" : {
"aliases" : { },
"mappings" : {
"properties" : {
"event" : {
"properties" : {
"duri" : {
"properties" : {
"identifier" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"uri" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"type" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"nUri" : {
"properties" : {
"identifier" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"uri" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"identifier" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"lastChangeDateTime" : {
"type" : "date"
},
"onUri" : {
"properties" : {
"identifier" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"uri" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"sequence" : {
"type" : "long"
},
"uri" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"event2" : {
"properties" : {
"iTypes" : {
"properties" : {
"description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"code" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"identifier" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"lastChangeDateTime" : {
"type" : "date"
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"tCode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"uri" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"event3" : {
"properties" : {
"code" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"identifier" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"lastChangeDateTime" : {
"type" : "date"
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"uri" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
},
"event4" : {
"properties" : {
"pUri" : {
"properties" : {
"identifier" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"uri" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"status" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"creator" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"identifier" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"language" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"lastChangeDateTime" : {
"type" : "date"
},
"sUrl" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"subject" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"subjectURI" : {
"properties" : {
"identifier" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"uri" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"uri" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"version" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"event5" : {
"properties" : {
"docUri" : {
"properties" : {
"identifier" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"uri" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"event45" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"itemUri" : {
"properties" : {
"identifier" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"uri" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"edLevels" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"statement" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"hcs" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"identifier" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"language" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"lastChangeDateTime" : {
"type" : "date"
},
"list" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"notes" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"uri" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"testField" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"settings" : {
"index" : {
"routing" : {
"allocation" : {
"include" : {
"_tier_preference" : "data_content"
}
}
},
"number_of_shards" : "1",
"provided_name" : "taxonomies",
"creation_date" : "1654273882675",
"number_of_replicas" : "1",
"uuid" : "ychbqd9GTzC-arQgLib_RQ",
"version" : {
"created" : "7130099"
}
}
}
}
}