0

Good morning, In my code I can't search data which contain separate words. If I search on one word all good. I think problem in mapping. I use postman. When I put in URL http://192.168.1.153:9200/sport_scouts/video/_mapping and use method GET I get:

{
  "sport_scouts": {
    "mappings": {
      "video": {
        "properties": {
          "hashtag": {
            "type": "string"
          },
          "id": {
            "type": "long"
          },
          "sharing_link": {
            "type": "string"
          },
          "source": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "user_id": {
            "type": "long"
          },
          "video_preview": {
            "type": "string"
          }
        }
      }
    }
  }
}  

All good title have type string but if I search on two or more words I get empty massive. My code in Trait:

public function search($data) {

        $this->client();

        $params['body']['query']['filtered']['filter']['or'][]['term']['title'] = $data;
        $search = $this->client->search($params)['hits']['hits'];
        dump($search);
    }  

Then I call it in my Controller. Can you help me with this problem?

2
  • 1
    What's the problem you are having? Commented Jul 19, 2016 at 7:57
  • The elastic doesn't search on two or more words, it return empty massive, elastic search only on one word. Commented Jul 19, 2016 at 8:05

1 Answer 1

1

The reason that your indexed data can't be found is caused by a mismatch of the analyzing during indexing and a strict term filter when querying the data.

With your mapping configuration, you are using the default analyzing which (besides many other operations) does a tokenizing. So every multi-word data you insert is split at punctuation or whitespaces. If you insert for example "some great sentence", elasticsearch maps the following terms to your document: "some", "great", "sentence", but not the term "great sentence". So if you do a term filter on "great sentence" or any other part of the original value containing a whitespace, you will not get any results.

Please see the elasticsearch docs on how to configure your mapping for indexing without analyzing (https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-intro.html#_index_2) or consider doing a match query instead of a term filter on the existing mapping (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html).

Please be aware that if you switch to not_analyzed you will be disabling many of the great fuzzy fulltext query functionality. Of course you can set up a mapping that does both, analyzed and not_analyzed in different fields. Then it's up on you to decide on which field you want to query on.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.