0
votes

I am using elastic search version 2.x. And I have two records which are indexed as:

  1. bathroom wall tile (as "nickname" indexed document column)
  2. tile wall bathroom (as "nickname" indexed document column)

When I am trying to search for phrase "tile wall bathroom" ideally second should appear first because that is exact match and after that first will appear because all the 3 words matches(tile, wall and bathroom).

I put sorting in my query based on columns. Below is my elastic search query:

{
                          "query" : {
                                "filtered" : {
                                      "query" : {
                                            "query_string": {
                                                "query": "*tile wall bathroom*",
                                                "fields": [
                                                    "nickname",
                                                    "comments",
                                                    "category_name",
                                                    "subcategory_name",
                                                    "document_name",
                                                    "web_links",
                                                    "document_extension",
                                                    "property_name",
                                                    "document_content"
                                                ],                                                    
                                                "analyze_wildcard": true
                                            }
                                      },
                                      "filter" : { 
                                            "and" : [
                                                  {"term" : {"property_id" : "6"}}
                                            ]
                                      }
                                }
                          },
                          "size": 10,
                          "sort": ["nickname", "comments", "web_links", "document_name"]
                    }

For reference please find attached image.enter image description here

Thanks in advance!!!

2

2 Answers

1
votes

All of your 3 terms hit, since both document-fields consist of "bathroom", "tile" and "wall". So it is common to retrieve both documents as hits. As you suggest, in general when sorted by score the first document should be ranked higher than the second one.

Since your first sort-field is the "nickname"-field, you get this result set where firstly all documents are sorted in alphabetical order on their "nickname"-fields (b in "bathroom wall tile" comes before t "tile wall bathroom", etc). This excludes sort by relevance-score on your search-request. You may use "nickname" as secondary sort parameter and the "_score"-field as first one instead.

You may as well check your query with the Elasticsearch-explain functionality.

Cheers, Dominik

Edit: Please try to run your query against the Elasticsearch-Explain-API, which enables to understand how your result has been computed. Furthermore, you may run a match-query against your data to see if your results improve against the usage of "query_string". Hereby, you may also leave out the sort-parameters to rank the results only by their relevance-score.

{
    "query": {
        "match": {
            "nickname": "tile wall bathroom"
        },
        "size": 10,
        "sort": ["_score", "nickname", "comments", "web_links", "document_name"]
    }
}
0
votes

You should be using shingles. Your use case is specifically what they were designed for.