Skip to content

Instantly share code, notes, and snippets.

@mikeyoon
Created October 2, 2012 19:17
Show Gist options
  • Save mikeyoon/3822664 to your computer and use it in GitHub Desktop.
Save mikeyoon/3822664 to your computer and use it in GitHub Desktop.
ElasticSearch Synonym Repro
synonyms.txt
test => Washington Nationals, New England Patriots
curl -XGET "http://172.16.10.244:9200/dev-events/_analyze?analyzer=sb_analyzer&pretty=true" -d "test"
{
"tokens" : [ {
"token" : "washington",
"start_offset" : 0,
"end_offset" : 4,
"type" : "SYNONYM",
"position" : 1
}, {
"token" : "new",
"start_offset" : 0,
"end_offset" : 4,
"type" : "SYNONYM",
"position" : 1
}, {
"token" : "nation",
"start_offset" : 0,
"end_offset" : 4,
"type" : "SYNONYM",
"position" : 2
}, {
"token" : "england",
"start_offset" : 0,
"end_offset" : 4,
"type" : "SYNONYM",
"position" : 2
}, {
"token" : "patriot",
"start_offset" : 0,
"end_offset" : 4,
"type" : "SYNONYM",
"position" : 3
} ]
}
search-test.json
{
"fields" : [ "name" ],
"query" : {
"query_string" :
{
"query" : "test",
"analyzer" : "sb_analyzer",
"fields" : [ "name", "primaryPerformer", "secondaryPerformer" ],
"auto_generate_phrase_queries" : true
}
},
"sort" : [
{
"localDateTime" : { "order" : "asc" }
}
],
"size" : 5
}
type search-test.json | http GET -u "http://172.16.10.244:9200/dev-events/_search?pretty=true"
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 1502
{
"took" : 21,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 12,
"max_score" : null,
"hits" : [ {
"_index" : "dev-events",
"_type" : "event",
"_id" : "fa2694d2-edaa-43d7-bbf6-a08a00c92ec3",
"_score" : null,
"fields" : {
"name" : "Buffalo Bills vs. New England Patriots"
},
"sort" : [ 1349010000000 ]
}, {
"_index" : "dev-events",
"_type" : "event",
"_id" : "fda02c59-5bb0-41c1-86c9-a08b01270bb8",
"_score" : null,
"fields" : {
"name" : "New England Patriots vs. Denver Broncos"
},
"sort" : [ 1349626500000 ]
}, {
"_index" : "dev-events",
"_type" : "event",
"_id" : "26c2e203-971f-4b10-b483-a09a012293ff",
"_score" : null,
"fields" : {
"name" : "Seattle Seahawks vs. New England Patriots"
},
"sort" : [ 1350219600000 ]
}, {
"_index" : "dev-events",
"_type" : "event",
"_id" : "cdf4a4d3-017a-41d5-aeb6-a08b01273874",
"_score" : null,
"fields" : {
"name" : "New England Patriots vs. New York Jets"
},
"sort" : [ 1350836100000 ]
}, {
"_index" : "dev-events",
"_type" : "event",
"_id" : "5fb293ce-6fdb-4ace-966b-a08b01274fb4",
"_score" : null,
"fields" : {
"name" : "New England Patriots vs. Buffalo Bills"
},
"sort" : [ 1352638800000 ]
} ]
}
}
search-ne.json
{
"fields" : [ "name" ],
"query" : {
"query_string" :
{
"query" : "New AND England AND Patriots",
"analyzer" : "sb_analyzer",
"fields" : [ "name", "primaryPerformer", "secondaryPerformer" ],
"auto_generate_phrase_queries" : true
}
},
"sort" : [
{
"localDateTime" : { "order" : "asc" }
}
],
"size" : 5
}
type search-ne.json | http GET -u "http://172.16.10.244:9200/dev-events/_search?pretty=true"
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 1501
{
"took" : 8,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 12,
"max_score" : null,
"hits" : [ {
"_index" : "dev-events",
"_type" : "event",
"_id" : "fa2694d2-edaa-43d7-bbf6-a08a00c92ec3",
"_score" : null,
"fields" : {
"name" : "Buffalo Bills vs. New England Patriots"
},
"sort" : [ 1349010000000 ]
}, {
"_index" : "dev-events",
"_type" : "event",
"_id" : "fda02c59-5bb0-41c1-86c9-a08b01270bb8",
"_score" : null,
"fields" : {
"name" : "New England Patriots vs. Denver Broncos"
},
"sort" : [ 1349626500000 ]
}, {
"_index" : "dev-events",
"_type" : "event",
"_id" : "26c2e203-971f-4b10-b483-a09a012293ff",
"_score" : null,
"fields" : {
"name" : "Seattle Seahawks vs. New England Patriots"
},
"sort" : [ 1350219600000 ]
}, {
"_index" : "dev-events",
"_type" : "event",
"_id" : "cdf4a4d3-017a-41d5-aeb6-a08b01273874",
"_score" : null,
"fields" : {
"name" : "New England Patriots vs. New York Jets"
},
"sort" : [ 1350836100000 ]
}, {
"_index" : "dev-events",
"_type" : "event",
"_id" : "5fb293ce-6fdb-4ace-966b-a08b01274fb4",
"_score" : null,
"fields" : {
"name" : "New England Patriots vs. Buffalo Bills"
},
"sort" : [ 1352638800000 ]
} ]
}
}
search-wash.json
{
"fields" : [ "name" ],
"query" : {
"query_string" :
{
"query" : "Washington AND Nationals",
"analyzer" : "sb_analyzer",
"fields" : [ "name", "primaryPerformer", "secondaryPerformer" ],
"auto_generate_phrase_queries" : true
}
},
"sort" : [
{
"localDateTime" : { "order" : "asc" }
}
],
"size" : 5
}
type search-wash.json | http GET -u "http://172.16.10.244:9200/dev-events/_search?pretty=true"
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 1530
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 6,
"max_score" : null,
"hits" : [ {
"_index" : "dev-events",
"_type" : "event",
"_id" : "69e1b400-e213-4cd5-aed6-a00b00dadda6",
"_score" : null,
"fields" : {
"name" : "St. Louis Cardinals vs. Washington Nationals"
},
"sort" : [ 1348859700000 ]
}, {
"_index" : "dev-events",
"_type" : "event",
"_id" : "3dc94c8b-cc0f-4a04-ab11-a00b00db05e1",
"_score" : null,
"fields" : {
"name" : "St. Louis Cardinals vs. Washington Nationals"
},
"sort" : [ 1348942500000 ]
}, {
"_index" : "dev-events",
"_type" : "event",
"_id" : "8c154cd4-6379-4272-b05a-a00b00db135c",
"_score" : null,
"fields" : {
"name" : "St. Louis Cardinals vs. Washington Nationals"
},
"sort" : [ 1349010900000 ]
}, {
"_index" : "dev-events",
"_type" : "event",
"_id" : "c0140d34-5bd7-4ada-aeb7-9ff00135e652",
"_score" : null,
"fields" : {
"name" : "Washington Nationals vs. Philadelphia Phillies"
},
"sort" : [ 1349118300000 ]
}, {
"_index" : "dev-events",
"_type" : "event",
"_id" : "da5adbe5-ea23-45d4-9472-9ff00135eecd",
"_score" : null,
"fields" : {
"name" : "Washington Nationals vs. Philadelphia Phillies"
},
"sort" : [ 1349204700000 ]
} ]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment