# Cannot get term payloads to work

**URL:** <https://discuss.elastic.co/t/cannot-get-term-payloads-to-work/8026>\
**Category:** Elasticsearch\
**Created:** [June 8, 2012, 11:07pm UTC](https://discuss.elastic.co/t/cannot-get-term-payloads-to-work/8026 "2012-06-08T23:07:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wojtek](https://avatars.discourse-cdn.com/v4/letter/w/c77e96/32.png) [@wojtek](https://discuss.elastic.co/u/wojtek)\
**Post date:** [June 8, 2012, 11:07pm UTC](https://discuss.elastic.co/t/cannot-get-term-payloads-to-work/8026/1 "2012-06-08T23:07:21Z")

</div>

Hi,

I've spent several days trying to achieve something like this in ES:

[http://www.lucidimagination.com/search/link?url=http://wiki.apache.org/solr/Payloads](http://www.lucidimagination.com/search/link?url=http://wiki.apache.org/solr/Payloads)

But had no luck.

This is what I did (maybe all of that in unnecessary, but I couldn't find  
any information on how to do this correctly):

- Created a custom similarity and a provider (mimicking  
[https://github.com/tlrx/elasticsearch-custom-similarity-provider](https://github.com/tlrx/elasticsearch-custom-similarity-provider) )

- Created a custom analyzer:

where the payload filter just does:

```
@Override
public TokenStream create(TokenStream tokenStream) {
    return new DelimitedPayloadTokenFilter(tokenStream, '|', new 

```

FloatEncoder());  
}

- created an index that uses that similarity for index and search and that  
analyzer.
- Created a mapping that instructs to use the new analyzer when indexing  
field "message"
- indexed a document:

curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
"tweet" : {  
"user" : "kimchy",  
"message" : "search|40.0"  
}  
}'

Did a search for term "search", but looking at the query "explain" the  
payload doesn't seem to be taken into account.

Also when I retrieve the document back, I see the content of "message" to  
be exactly like I submitted to indexing (including the pipe and payload)  
not sure this is a bad sign.

Please let me know what I'm doing wrong here.

---

<div class="post-metadata">

**Author:** ![wojtek](https://avatars.discourse-cdn.com/v4/letter/w/c77e96/32.png) [@wojtek](https://discuss.elastic.co/u/wojtek)\
**Post date:** [June 9, 2012, 12:42am UTC](https://discuss.elastic.co/t/cannot-get-term-payloads-to-work/8026/2 "2012-06-09T00:42:14Z")

</div>

I made some progress. Turns out I needed to set the pf analyzer on the \_all  
field, so that in combination with AllTermsQuery it works properly.

What should I do if I want this to work on searches restricted to the  
"message" field?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 12, 2012, 10:05am UTC](https://discuss.elastic.co/t/cannot-get-term-payloads-to-work/8026/3 "2012-06-12T10:05:46Z")

</div>

You can simply set the analyzer on the mentioned field and explicitly  
search for it. The \_all field is a special field that includes all the  
other fields.

On Sat, Jun 9, 2012 at 2:42 AM, wojtek [wojciech.jawor@gmail.com](mailto:wojciech.jawor@gmail.com) wrote:

> I made some progress. Turns out I needed to set the pf analyzer on the  
> \_all field, so that in combination with AllTermsQuery it works properly.
> 
> What should I do if I want this to work on searches restricted to the  
> "message" field?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:24am UTC](https://discuss.elastic.co/t/cannot-get-term-payloads-to-work/8026/4 "2017-07-06T03:24:49Z")

</div>


