Created
June 10, 2011 10:16
-
-
Save vhyza/1018584 to your computer and use it in GitHub Desktop.
Elasticsearch fields test
This file contains hidden or 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
# Remove index | |
curl -s -XDELETE "http://localhost:9200/fields_test" | |
# Set new index with mapping | |
curl -s -XPUT "http://localhost:9200/fields_test" -d ' | |
{ | |
"mappings": { | |
"tweet" : { | |
"properties" : { | |
"person" : { | |
"type" : "object", | |
"properties" : { | |
"name" : { | |
"properties" : { | |
"first_name" : {"type" : "string"}, | |
"last_name" : {"type" : "string"} | |
} | |
}, | |
"sid" : {"type" : "string", "index" : "not_analyzed"} | |
} | |
}, | |
"message" : {"type" : "string", "store" : "no", "index" : "not_analyzed"} | |
} | |
} | |
} | |
}' | |
# Insert new tweet | |
curl -s -X POST 'http://localhost:9200/fields_test/tweet' -d ' { | |
"person" : { | |
"name" : { | |
"first_name" : "Shay", | |
"last_name" : "Banon" | |
}, | |
"sid" : "12345" | |
}, | |
"message" : "This is a tweet!" | |
}' | |
curl -s -X POST 'http://localhost:9200/fields_test/_refresh' | |
# Response doesn't contain person field. Message is returned ok (and its not stored and not analyzed) | |
curl -s "http://localhost:9200/fields_test/_search?pretty=1" -d '{ | |
"fields" : ["message", "person"], | |
"query": { "query_string" : { "query" : "Shay"} } | |
}' | |
# When requesting _source.person, then its returned ok. Seems fields param has problem with type: object | |
curl -s "http://localhost:9200/fields_test/_search?pretty=1" -d '{ | |
"fields" : ["message", "_source.person"], | |
"query":{ "query_string" : { "query" : "Shay"} } | |
}' |
Hello @mchruszcz. Please can you gist whole your test suite (with whole mapping, document creating and searching)? Its hard for me to recreate behaviour which you described.
@vhyza, I described it in https://gist.github.com/1300910.
@mchruszcz thanks. I'm not sure if I understand it correctly. According this discussion karmi/retire#31 you have to add _source
prefix before compound fields. I don't know if its possible to request one field of object type.
@kimchy, please, is somehow possible to have only one object field in fields response (as described in https://gist.github.com/1300910)?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The same behaviour might be observed with arrays. Having a mapping like this:
querying for
images
won't return any images. Replacing it with_source.images
will work, though. I still, however, can't figure out how to query for single fields, e.g.images.title
(_source.images.title
doesn't work).