Sto provando a interrogare proprietà nidificate con più valori.Cerca un campo nidificato per più valori sullo stesso campo con elasticsearch
Ecco un esempio che sarà più chiaro.
Creare un indice con un campo nidificato
curl -X DELETE "http://localhost:9200/testing_nested_query/"
curl -X POST "http://localhost:9200/testing_nested_query/" -d '{
"mappings": {
"class": {
properties: {
title: {"type": "string"},
"students": {
"type": "nested",
"properties": {
"name": {"type": "string"}
}
}
}
}
}
}'
Aggiungere alcuni valori
curl -XPUT 'http://localhost:9200/testing_nested_query/class/1' -d '{
"title": "class1",
"students": [{"name": "john"},{"name": "jack"},{"name": "jim"}]
}'
curl -XPUT 'http://localhost:9200/testing_nested_query/class/2' -d '{
"title": "class2",
"students": [{"name": "john"},{"name": "chris"},{"name": "alex"}]
}'
query per tutte le classi in cui John è (2 risultati come previsto)
curl -XGET 'http://localhost:9200/testing_nested_query/class/_search' -d '{
"query": {
"nested": {
"path":"students",
"query": {
"bool": {
"must": [
{"match": {"students.name": "john"}}
]
}
}
}
}
}'
query per le classi in cui entrambi John e Jack sono Parteciperò (0 risultati invece di 1)
curl -XGET 'http://localhost:9200/testing_nested_query/class/_search' -d '{
"query": {
"nested": {
"path":"students",
"query": {
"bool": {
"must": [
{"match": {"students.name": "john"}},
{"match": {"students.name": "jack"}}
]
}
}
}
}
}'
ho provato con la corrispondenza e filtro ma non posso mai avere la query per restituire i valori previsti.
La query avrebbe funzionato semplicemente usando "dovrebbe" invece di "deve". – plmaheu
No, con "dovrebbe" Restituisce 2 colpi invece di uno. –
Hai ragione, ho letto male la domanda. – plmaheu