Facet of whole value of analyzed field instead of tokens

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Facet of whole value of analyzed field instead of tokens

Ankit Jain
Hi All,

We have index mapping as mentioned below.

{
    "test" : {
        "tweet" : {
            "properties" : {
                "content1" : {
                    "type" : "string"
                },
                "message" : {
                    "type" : "string",
                    "store" : true
                }
            }
        }
    }
}

The value of field message is "won match test" and have inserted 10 records of similar type. On term facet over value, we are getting facet count 30 for value "won match test" while we are expecting total count 10.


        TermsFacetBuilder termsFacetBuilder = FacetBuilders.termsFacet(
                "combine").fields("message").scriptField("_fields.message.value ").size(100);
       
        SearchRequestBuilder searchRequestBuilder = client
                .prepareSearch("test")
                .setSearchType(SearchType.QUERY_THEN_FETCH)
                .addFacet(termsFacetBuilder).setSize(10000);
        SearchResponse searchResponse = searchRequestBuilder.execute()
                .actionGet();
        TermsFacet f = (TermsFacet) searchResponse.getFacets().facetsAsMap()
                .get("combine");
       
        System.out.println(f.getTotalCount()); // Total terms doc count
        System.out.println(f.getOtherCount()); // Not shown terms doc count
        System.out.println(f.getMissingCount()); // Without term doc count
        // For each entry
        for (TermsFacet.Entry entry : f) {           
            System.out.println(entry.getTerm());
            System.out.println(entry.getCount());
        }
   

Please help.

Regards,
Ankit Jain



--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Facet of whole value of analyzed field instead of tokens

Dan Tuffery
Hi,

The the facet field should not be analyzed and you don't need to store it either as the indexed value is used for display purposes. For the message property make the type 'multi_field' , index an analyzed version of 'message' (for searching) and and not analyzed version of your field (for faceting):

{
    "test" : {
        "tweet" : {
            "properties" : {
                "content1" : {
                    "type" : "string"
                },
                "message" : {
                    "type": "multi_field",
                    "fields":{
                        "message":{
                            "type":"string",
                            "index":"analyzed",
                            "store":"true"
                        },
                        "untouched": {
                            "type": "string",
                            "index": "not_analyzed"
                        }
                    }
                   
                }
            }
        }
    }
}

When you create your TermFacetBuilder use:

TermsFacetBuilder facetBuilder =   FacetBuilders.termsFacet("Message").field("message.untouched");

Dan



On Monday, November 11, 2013 2:07:27 PM UTC, Ankit Jain wrote:
Hi All,

We have index mapping as mentioned below.

{
    "test" : {
        "tweet" : {
            "properties" : {
                "content1" : {
                    "type" : "string"
                },
                "message" : {
                    "type" : "string",
                    "store" : true
                }
            }
        }
    }
}

The value of field message is "won match test" and have inserted 10 records of similar type. On term facet over value, we are getting facet count 30 for value "won match test" while we are expecting total count 10.


        TermsFacetBuilder termsFacetBuilder = FacetBuilders.termsFacet(
                "combine").fields("message").scriptField("_fields.message.value ").size(100);
       
        SearchRequestBuilder searchRequestBuilder = client
                .prepareSearch("test")
                .setSearchType(SearchType.QUERY_THEN_FETCH)
                .addFacet(termsFacetBuilder).setSize(10000);
        SearchResponse searchResponse = searchRequestBuilder.execute()
                .actionGet();
        TermsFacet f = (TermsFacet) searchResponse.getFacets().facetsAsMap()
                .get("combine");
       
        System.out.println(f.getTotalCount()); // Total terms doc count
        System.out.println(f.getOtherCount()); // Not shown terms doc count
        System.out.println(f.getMissingCount()); // Without term doc count
        // For each entry
        for (TermsFacet.Entry entry : f) {           
            System.out.println(entry.getTerm());
            System.out.println(entry.getCount());
        }
   

Please help.

Regards,
Ankit Jain



--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.