hello,
here some sample data:
settings and mappings:
{ "settings":{ "analysis":{ "filter":{ "my_synonym_filter":{ "type":"synonym", "synonyms": [ "synonym0 => owl shirt" ] } }, "analyzer":{ "test_analyzer":{ "type":"custom", "tokenizer":"standard", "filter":[ "my_synonym_filter" ] } } } }, "mappings":{ "test":{ "properties":{ "id":{ "type":"string", "index":"not_analyzed" }, "field0":{ "type":"string", "index":"analyzed" }, "field1":{ "type":"string", "index":"analyzed" }, "field2":{ "type":"string", "index":"analyzed" } } } } }
data:
{"index":{"_type":"test","_id":"0"}} {"field0":"product 0","field1":"","field2":"owl,shirt"} {"index":{"_type":"test","_id":"1"}} {"field0":"product 1","field1":"shirt","field2":"owl"} {"index":{"_type":"test","_id":"2"}} {"field0":"product 2","field1":"shirt","field2":"horse"} {"index":{"_type":"test","_id":"3"}} {"field0":"product 3","field1":"longsleeve","field2":"penguin"}
when i search like this:
POST /syntest/test/_search?pretty { "query":{ "query_string":{ "query":"shirt owl", "default_operator":"AND", "analyzer":"test_analyzer", "fields":[ "field1", "field2" ] } } }
i get as aspected all results which contains shirt and owl in fields field1 and field2:
{ "took": 7, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 2, "max_score": 0.13316044, "hits": [ { "_index": "syntest", "_type": "test", "_id": "1", "_score": 0.13316044, "_source": { "field0": "product 1", "field1": "shirt", "field2": "owl" } }, { "_index": "syntest", "_type": "test", "_id": "0", "_score": 0.08322528, "_source": { "field0": "product 0", "field1": "", "field2": "owl,shirt" } } ] } }
but when i search with the defined synonym synonym0 i get just one result:
POST /syntest/test/_search?pretty { "query":{ "query_string":{ "query":"synonym0", "default_operator":"AND", "analyzer":"test_analyzer", "fields":[ "field1", "field2" ] } } }
{ "took": 6, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1, "max_score": 0.08322528, "hits": [ { "_index": "syntest", "_type": "test", "_id": "0", "_score": 0.08322528, "_source": { "field0": "product 0", "field1": "", "field2": "owl,shirt" } } ] } }
what is the problem?
tested with elasticsearch 2.2.
tanks