0
votes

I have an Elastic Search project with my aggregation and filter working correctly before I added synonym analyzer to mapping. Current working Mapping :

"settings": {
        "analysis": {
            "normalizer": {
                "lowercase": {
                "type": "custom",
                "filter": ["lowercase"]
                }
            }
        }
    },
 "mappings": {
        "doc": {
            "dynamic": "false",
            "properties": {
              "primarytrades": {
                    "type": "nested",
                    "properties" :{
                        "name": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256,
                                    "normalizer": "lowercase"
                                }
                            }
                        }
                     }
                   }
                }
             }
          }

#This is request and response with expected bucketed values:

Request: {"aggs":{"filter_trades":{"aggs":{"nested_trades":{"aggs":{"autocomplete_trades":{"terms":{"field":"primarytrades.name.keyword","include":".*p.*l.*u.*m.b.","size":10}}},"nested":{"path":"primarytrades"}}},"filter":{"nested":{"path":"primarytrades","query":{"bool":{"should":[{"match":{"primarytrades.name":{"fuzziness":2,"query":"plumb"}}},{"match_phrase_prefix":{"primarytrades.name":{"query":"plumb"}}}]}}}}}},"query":{"bool":{"filter":[{"nested":{"path":"primarytrades","query":{"bool":{"should":[{"match":{"primarytrades.name":{"fuzziness":2,"query":"plumb"}}},{"match_phrase_prefix":{"primarytrades.name":{"query":"plumb"}}}]}}}}]}},"size":0}

Response: {"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":7216,"max_score":0.0,"hits":[]},"aggregations":{"filter#filter_trades":{"doc_count":7216,"nested#nested_trades":{"doc_count":48496,"sterms#autocomplete_trades":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"plumbing","doc_count":7192},{"key":"plumbing parts","doc_count":179}]}}}}}

To add synonym search feature to this, I changed mapping with synonym analyzer like this :

 "settings": {
      "analysis": {
        "normalizer": {
          "lowercase": {
            "type": "custom",
            "filter": [ "lowercase" ]
          }
        },
        "analyzer": {
          "synonym_analyzer": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": [ "lowercase", "my_synonyms" ]
          }
        },
        "filter": {
          "my_synonyms": {
            "type": "synonym",
            "synonyms": [ "piping, sink, plumbing" ],
            "updateable": true
          }
        }
      }
    },
    "mappings": {
        "doc": {
            "dynamic": "false",
            "properties": {
                "primarytrades": {
                    "type": "nested",
                    "properties" :{
                      "name": {
                        "type": "text",
                        "fields": {
                          "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                          },
                          "analyzed": {
                            "type": "text",
                            "analyzer": "standard",
                            "search_analyzer": "synonym_analyzer"
                          }
                        }
                      }
                    }
              }
        }
    }
}

And also, I changed my query to use search_analyzer as below :

{"aggs":{"filter_trades":{"aggs":{"nested_trades":{"aggs":{"autocomplete_trades":{"match":{"field":"primarytrades.name.analyzed","include":".*p.*l.*u.*m.b.","size":10}}},"nested":{"path":"primarytrades"}}},"filter":{"nested":{"path":"primarytrades","query":{"bool":{"should":[{"match":{"primarytrades.name":{"fuzziness":2,"query":"plumb","search_analyzer":"synonym_analyzer"}}},{"match_phrase_prefix":{"primarytrades.name":{"query":"plumb","search_analyzer":"synonym_analyzer"}}}]}}}}}},"query":{"bool":{"filter":[{"nested":{"path":"primarytrades","query":{"bool":{"should":[{"match":{"primarytrades.name":{"fuzziness":2,"query":"plumb","search_analyzer":"synonym_analyzer"}}},{"match_phrase_prefix":{"primarytrades.name":{"query":"plumb","search_analyzer":"synonym_analyzer"}}}]}}}}]}}}

I am getting this error : "type": "named_object_not_found_exception", "reason": "[8:24] unable to parse BaseAggregationBuilder with name [match]: parser not found"

Can someone help me correct the query ?

Thanks in advance!

1
for aggregation I tried "field": "primarytrades.name.analyzed" on "significant_text" and the error goes away but I don't get any values for my buckets. Similarly I used "field": "primarytrades.name.keyword" on "terms" and I don't get any values for buckets. How can I get bucket values based on my synonym analyzer and filters ?user2506233

1 Answers

0
votes

In your match queries, you need to specify analyzer and not search_analyzer. search_analyzer is only a valid keyword in the mapping section.

              {
                "match": {
                  "primarytrades.name": {
                    "fuzziness": 2,
                    "query": "plumb",
                    "analyzer": "synonym_analyzer"      <--- change this
                  }
                }
              },