Skip to content

Instantly share code, notes, and snippets.

@ofavre
Created June 23, 2011 12:56
Show Gist options
  • Save ofavre/1042483 to your computer and use it in GitHub Desktop.
Save ofavre/1042483 to your computer and use it in GitHub Desktop.
include_in_all ignored for multi_fields
curl -XDELETE 'localhost:9200/index'
{"ok":true,"acknowledged":true}
curl -XPUT 'localhost:9200/index' -d '{"settings":{"index":{"number_of_shards":1,"number_of_replicas":0}}}'
{"ok":true,"acknowledged":true}
# The mapping I would like
curl -XPUT 'localhost:9200/index/type/_mapping' -d '{
"type":{
"_source":{ "enabled":false },
"_all":{ "enabled":true },
"properties":{
"text":{
"type":"string",
"store":true,
"index":"no",
"include_in_all":true
}
}
}
}'
{"ok":true,"acknowledged":true}
curl -XPUT 'localhost:9200/index/type/1' -d '{
"text":"foobar"
}'
{"ok":true,"_index":"index","_type":"type","_id":"1","_version":1}
curl -XPOST 'localhost:9200/index/_optimize?refresh=true&flush=true&wait_for_merge=true'
{"ok":true,"_shards":{"total":1,"successful":1,"failed":0}}
curl -XGET 'localhost:9200/index/type/_search?pretty=1&fields=*' -d '{
"query":{
"term":{
"text":"foobar"
}
}
}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
curl -XGET 'localhost:9200/index/type/_search?pretty=1&fields=*' -d '{
"query":{
"term":{
"_all":"foobar"
}
}
}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.2169777,
"hits" : [ {
"_index" : "index",
"_type" : "type",
"_id" : "1",
"_score" : 0.2169777,
"fields" : {
"text" : "foobar"
}
} ]
}
}
curl -XGET 'localhost:9200/index/type/_search?pretty=1&fields=*' -d '{
"query":{
"query_string":{
"query": "foobar"
}
}
}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.2169777,
"hits" : [ {
"_index" : "index",
"_type" : "type",
"_id" : "1",
"_score" : 0.2169777,
"fields" : {
"text" : "foobar"
}
} ]
}
}
curl -XDELETE 'localhost:9200/index'
{"ok":true,"acknowledged":true}
curl -XPUT 'localhost:9200/index' -d '{"settings":{"index":{"number_of_shards":1,"number_of_replicas":0}}}'
{"ok":true,"acknowledged":true}
# The mapping I would like
curl -XPUT 'localhost:9200/index/type/_mapping' -d '{
"type":{
"_source":{ "enabled":false },
"_all":{ "enabled":true },
"properties":{
"text":{
"type":"multi_field",
"include_in_all":true,
"fields":{
"one":{
"type":"string",
"store":false,
"index":"not_analyzed"
},
"two":{
"type":"string",
"store":false,
"index":"not_analyzed"
},
"text":{
"type":"string",
"store":true,
"index":"not_analyzed",
"include_in_all":true,
"term_vector":"with_positions_offsets"
}
}
}
}
}
}'
{"ok":true,"acknowledged":true}
curl -XPUT 'localhost:9200/index/type/1' -d '{
"text":"foobar"
}'
{"ok":true,"_index":"index","_type":"type","_id":"1","_version":1}
curl -XPOST 'localhost:9200/index/_optimize?refresh=true&flush=true&wait_for_merge=true'
{"ok":true,"_shards":{"total":1,"successful":1,"failed":0}}
curl -XGET 'localhost:9200/index/type/_search?pretty=1&fields=*' -d '{
"query":{
"term":{
"text":"foobar"
}
}
}'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.30685282,
"hits" : [ {
"_index" : "index",
"_type" : "type",
"_id" : "1",
"_score" : 0.30685282,
"fields" : {
"text" : "foobar"
}
} ]
}
}
curl -XGET 'localhost:9200/index/type/_search?pretty=1&fields=*' -d '{
"query":{
"term":{
"text.one":"foobar"
}
}
}'
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.30685282,
"hits" : [ {
"_index" : "index",
"_type" : "type",
"_id" : "1",
"_score" : 0.30685282,
"fields" : {
"text" : "foobar"
}
} ]
}
}
curl -XGET 'localhost:9200/index/type/_search?pretty=1&fields=*' -d '{
"query":{
"term":{
"text.two":"foobar"
}
}
}'
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.30685282,
"hits" : [ {
"_index" : "index",
"_type" : "type",
"_id" : "1",
"_score" : 0.30685282,
"fields" : {
"text" : "foobar"
}
} ]
}
}
curl -XGET 'localhost:9200/index/type/_search?pretty=1&fields=*' -d '{
"query":{
"term":{
"_all":"foobar"
}
}
}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.2169777,
"hits" : [ {
"_index" : "index",
"_type" : "type",
"_id" : "1",
"_score" : 0.2169777,
"fields" : {
"text" : "foobar"
}
} ]
}
}
curl -XGET 'localhost:9200/index/type/_search?pretty=1&fields=*' -d '{
"query":{
"query_string":{
"query": "foobar"
}
},
"highlight":{
"fields":{
"text":{ "number_of_fragments":0 }
}
}
}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.2169777,
"hits" : [ {
"_index" : "index",
"_type" : "type",
"_id" : "1",
"_score" : 0.2169777,
"fields" : {
"text" : "foobar"
},
"highlight" : {
"text" : [ "<em>foobar</em>" ]
}
} ]
}
}
set +v
@ofavre
Copy link
Author

ofavre commented Jun 23, 2011

Use a subfield named exactly as the main field, it controls include_in_all.
Read http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html under Accessing Fields

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment