Skip to content

Instantly share code, notes, and snippets.

@vhyza
Created June 10, 2011 10:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vhyza/1018584 to your computer and use it in GitHub Desktop.
Save vhyza/1018584 to your computer and use it in GitHub Desktop.
Elasticsearch fields test
# 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"} }
}'
@mchruszcz
Copy link

The same behaviour might be observed with arrays. Having a mapping like this:

{
  "gallery": {
    "properties": {
      "title": {
        "type": "string"
      },
      "images": {
        "dynamic": "true",
        "properties": {
          "title": {
            "type": "string"
          }
        }
      }
    }
  }
}

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).

@vhyza
Copy link
Author

vhyza commented Oct 19, 2011

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.

@mchruszcz
Copy link

@vhyza
Copy link
Author

vhyza commented Oct 23, 2011

@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