-
-
Save imotov/737176fd5a0f60730db8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XDELETE localhost:9200/test-idx | |
curl -XPUT localhost:9200/test-idx -d '{ | |
"mappings": { | |
"ofertas": { | |
"properties": { | |
"idtipooa": { | |
"type": "nested", | |
"properties": { | |
"nombre": {"type": "string", "index": "not_analyzed" } | |
} | |
} | |
} | |
} | |
} | |
}' | |
echo | |
curl -XPUT localhost:9200/test-idx/ofertas/3 -d '{ | |
"id": 3, | |
"nombreoa": "Abogacia", | |
"titulo": "Abogado", | |
"idtipooa": { | |
"nombre": "Carrera Universitaria" | |
} | |
}' | |
echo | |
curl -XPOST localhost:9200/test-idx/_refresh | |
echo | |
echo | |
echo '== Searching for "Universitaria" - no results ==' | |
curl -XPOST "localhost:9200/test-idx/ofertas/_search?pretty=true" -d '{ | |
"query": { | |
"filtered": { | |
"query": { | |
"match_all": {} | |
}, | |
"filter": { | |
"nested": { | |
"path": "idtipooa", | |
"query": { | |
"bool": { | |
"must": [{ | |
"match": { | |
"idtipooa.nombre": "Universitaria" | |
} | |
}] | |
} | |
}, | |
"_cache": true | |
} | |
} | |
} | |
} | |
}' | |
echo | |
echo | |
echo '== Searching for "Carrera Universitaria" - one result ==' | |
curl -XPOST "localhost:9200/test-idx/ofertas/_search?pretty=true" -d '{ | |
"query": { | |
"filtered": { | |
"query": { | |
"match_all": {} | |
}, | |
"filter": { | |
"nested": { | |
"path": "idtipooa", | |
"query": { | |
"bool": { | |
"must": [{ | |
"match": { | |
"idtipooa.nombre": "Carrera Universitaria" | |
} | |
}] | |
} | |
}, | |
"_cache": true | |
} | |
} | |
} | |
} | |
}' |
Finally I got it. The mapping was wrong. It should be like that:
=> #<Elasticsearch::Model::Indexing::Mappings:0x0000010fb120a0
@mapping=
{:user=>{:type=>"object", :properties=>{:name=>{:type=>"string"}}},
:reservation=>
{:type=>"nested",
:properties=>
{:time_start=>{:type=>"string"},
:service_location_lane=>
{:type=>"object", :properties=>{:name=>{:type=>"string"}}}}}},
@options={},
@type="employee_reservation">
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Igor! Thank you for the gist - it guided me to the proper query structure but finally I was unable to compose it using the gist and elasticsearch (v1.1.0) documentation. Here is what I have:
And here are the mappings:
Could you please point out my mistake? Thank you in advance!