Created
May 11, 2012 19:54
-
-
Save jprante/2662060 to your computer and use it in GitHub Desktop.
ISBN search tricks with Elasticsearch multi_field and index_name
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
curl -XDELETE 'localhost:9200/isbn/' | |
curl -XPUT 'localhost:9200/isbn/' -d ' | |
{ | |
"mappings" : { | |
"_default_" : { | |
"_source" : { | |
"enabled" : true | |
}, | |
"_all" : { | |
"analyzer" : "default", | |
"enabled" : true | |
}, | |
"properties" : { | |
"identifier" : { | |
"dynamic" : false, | |
"properties" : { | |
"isbn" : { | |
"type" : "string", | |
"include_in_all" : true | |
}, | |
"ean" : { | |
"type" : "multi_field", | |
"fields" : { | |
"ean" : { | |
"index_name" : "isbn", | |
"type" : "string" | |
}, | |
"eanonly" : { | |
"type" : "string" | |
} | |
} | |
}, | |
"isbnprintable" : { | |
"index_name" : "isbn", | |
"index" : "not_analyzed", | |
"type" : "string" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
' | |
# sample document | |
curl -XPUT 'localhost:9200/isbn/demo/1' -d ' | |
{ | |
"identifier" : { | |
"isbn" : "1932394281", | |
"ean" : "9781932394283", | |
"isbnprintable" : "1-932394-28-1" | |
} | |
} | |
' | |
sleep 1 | |
# hit | |
curl -XGET 'localhost:9200/isbn/demo/_search' -d ' | |
{ | |
"query" : { | |
"text" : { | |
"_all" : "1932394281" | |
} | |
} | |
} | |
' | |
# hit | |
curl -XGET 'localhost:9200/isbn/demo/_search' -d ' | |
{ | |
"query" : { | |
"text" : { | |
"_all" : "9781932394283" | |
} | |
} | |
} | |
' | |
# hit | |
curl -XGET 'localhost:9200/isbn/demo/_search' -d ' | |
{ | |
"query" : { | |
"text" : { | |
"identifier.isbn" : "1932394281" | |
} | |
} | |
} | |
' | |
# hit | |
curl -XGET 'localhost:9200/isbn/demo/_search' -d ' | |
{ | |
"query" : { | |
"text" : { | |
"identifier.isbn" : "9781932394283" | |
} | |
} | |
} | |
' | |
# hit :-( | |
curl -XGET 'localhost:9200/isbn/demo/_search' -d ' | |
{ | |
"query" : { | |
"text" : { | |
"identifier.ean" : "1932394281" | |
} | |
} | |
} | |
' | |
# hit | |
curl -XGET 'localhost:9200/isbn/demo/_search' -d ' | |
{ | |
"query" : { | |
"text" : { | |
"identifier.ean" : "9781932394283" | |
} | |
} | |
} | |
' | |
# hit | |
curl -XGET 'localhost:9200/isbn/demo/_search' -d ' | |
{ | |
"query" : { | |
"text" : { | |
"identifier.ean.eanonly" : "9781932394283" | |
} | |
} | |
} | |
' | |
# no hit :-) | |
curl -XGET 'localhost:9200/isbn/demo/_search' -d ' | |
{ | |
"query" : { | |
"text" : { | |
"identifier.ean.eanonly" : "1932394281" | |
} | |
} | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment