adamfairholm / elasticquent Goto Github PK
View Code? Open in Web Editor NEWMap Larvel Eloquent models to Elasticsearch types
License: MIT License
Map Larvel Eloquent models to Elasticsearch types
License: MIT License
My mappings look like this:
'ad_title' => [
'type' => 'string',
'analyzer' => 'standard'
],
'ad_type' => [
'type' => 'integer',
'index' => 'not_analyzed'
],
'ad_type' => [
'type' => 'integer',
'index' => 'not_analyzed'
],
'ad_state' => [
'type' => 'integer',
'index' => 'not_analyzed'
],
However when I view my mappings then 'index' => 'not_analyzed' wont show. I have made sure that I didnt have any existing data / remapped. Even made a new index. The 'index' => 'not_analyzed' will never show.
doing _mapping GET api call outputs my mapping as:
"testindex": {
"mappings": {
"ad_ad": {
"properties": {
"ad_city": {
"type": "integer"
},
"ad_id": {
"type": "long"
},
"ad_state": {
"type": "integer"
},
"ad_title": {
"type": "string",
"analyzer": "standard"
},
"ad_type": {
"type": "integer"
},
as you can see 'index' => 'not_analyzed' is not visible.
Asking on Stackoverflow someone posted me their output that looks like:
{
"hilden1": {
"mappings": {
"type1": {
"properties": {
"indexSpecified": {
"type": "string",
"index": "not_analyzed"
},
"regular": {
"type": "string"
}
}
}
}
}
}
As you can see "index": "not_analyzed" is visible.
So does Elasticquent dont support "index": "not_analyzed" ?
I'm using it in a project, but I found that I would like to have indexed some information from relationships. I know this have to be sent to ElastichSearch formated like Documents and Subdocuments, so if I have a Product, what can I do to have Product.type in ElasticSearch instead to Product.type_id ? Being Product.type a string with the name of the Type and type_id the Id of the Type.
Laravel 5 is almost out. Are there current plans to adapt the wonderful Elasticquent library to use this new version?
Hi,
I'm new with Elastic. I would like to search by multiple form fields.
For example I have my form with: company_name, contacts.first_last_name.
In my Elastic structure I have company_name, contacts.firstname, contacts.lastname
I want search by name (concat firstname and lastname) but if I filled the company_name form field I want to search company_name AND
firstname + lastname
I think it's working with concat field, but who to add other field ?
$clients = Client::searchByQuery([
'multi_match' => [
'query' => $request->get('first_last_name'),
"type" => "cross_fields",
'operator' => 'and',
'fields' => [
'contacts.firstname',
'contacts.lastname',
]
]
]);
Btw, how to add some checkboxes to the query with Elasticquent ? Of course, firstname, lastname and company_name will be included in the query too. I think it's a complex filter :/
Thx.
Suppose in a case we need to store all actions of users that they do with a record, for example a user with id 100 update the record with id 12 and we store that in a document, after that the same user or any other user updated the same record, or delete this record now we should store new document, and not replace the first one.
I am trying to install the package in composer by adding the following as stated:
"fairholm/elasticquent": "dev-master"
but I keep getting the following errors:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for fairholm/elasticquent dev-master -> satisfiable by fairholm/elasticquent[dev-master].
- fairholm/elasticquent dev-master requires illuminate/database ~4.2 -> no matching package found.
Potential causes:
Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.
That is my composer.json file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.",
"fzaninotto/faker": "^1.5",
"gloudemans/shoppingcart": "~1.3",
"elasticsearch/elasticsearch": "1.1.",
"illuminate/database": "^5.1",
"fairholm/elasticquent": "dev-master"
},
"require-dev": {
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-root-package-install": [
"php -r "copy('.env.example', '.env');""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
Any idea what is going wrong?!
Hello.
From what I understand, a search can be applied to an Eloquent Model.
What about searching a collection of models?
Instead of doing, for example, only this: Article::search('my post');
I would also need to do this: Article::where('category','news')->search('my post');
Is there any chance that we can see this in the near future?
Hello all - looking for some feedback on this.
Currently the way Elastiquent works is it uses the indexed source data in your Elasticsearch documents as the population data for your models. The whole idea behind using Elasticsearch is because it's super fast, so this way you are never hitting the database - you are bypassing that and using your indexed data only.
There are limitations to this, obviously - one being that you can only access data you have indexed, so you can't bust out relationships like you would when you are using Eloquent as you normally would. However, you can choose to index certain relationship data in your documents and search on those, allowing you to
So I'm wondering if Elastiquent needs functionality that allows you to hit the full database, using Elasticsearch as basically the search broker. So Elastiquent would search for the term and then do a FIELD
query to limit to IDs, allowing you to do whatever you'd like to that query. It's a method that pushes Elasticsearch further back in the process but it may offer an easier path to flexibility for those who need it.
Adam
Hello everyone,
Could someone help me to solve this problem?
Great work -- I've started using Elasticquent over the last day, and it works very nicely.
However, one issue I have is that ElasticquentResultCollection.php always expects aggregations to be returned from a search (line 26).
Most of the queries I'm doing at the moment don't need aggregations, and in order to prevent it throwing an error, I've had to change:
$this->aggregations = $results['aggregations'];
to:
$this->aggregations = isset($results['aggregations']) ? $results['aggregations'] : array();
After last update, (it upgrades elasticsearch from 1.3.2 to 1.3.3) i'm getting this error:
Undefined index: aggregations
Also, I have tried to comment that line, then it shows results but without sorting.
I'm using Elasticquent to work with mysql. When I update and insert data, the addAllToIndex and reindex methods works great. But when I want to delete something, the data that I deleted is still there.
How can I delete data in elasticquent?
Hello,
When I use this function, the search returns only 10 records of a collection. After some hours of studying, I've read that is something to do with 'from' and 'size', it's something to do with pagination.
How can I get all records or rize the number of records (size) using elasticquent?
Any example on how we can use highlighting?
@adamfairholm - Is there any chance we can cut a composer version on this? We are using this in a HIGHLY critical system here at UrtheCast and don't want to take any chances with future changes that we have not tested.
Thanks!
I wrote this by accident. Wrong browser tab. Late night.
How to index with eager loaded data?
Hi,
I am sorry about, maybe newbe question (I am beginner in this) but I am not sure how to use elasticquent...
so I did installed it into my app, elasticsearch also working fine, but not sure how to index data from model/s, tables? I have put
**use Elasticquent\ElasticquentTrait**;
class ModelName extends Eloquent {
**use ElasticquentTrait;**
}
into models, and now I am confused what next..
Do I need some new route which I would fire up and then in that route app will execute ModelName::addAllToIndex()
or some other way... And how to update index? is it going to do it by itself or I need something do execute with cron or something...
Tnx in advance for answer...
hello @adamfairholm , I am fairly new to laravel development so forgive me if I ask a stupid question.
thank you
Hi Adam,
Is it possible to apply boost on Individual fields with the caret (^) notation?
Like this sample:
{
"multi_match" : {
"query" : "this is a test",
"fields" : [ "subject^3", "message" ]
}
}
If it's possible, how to do this with your package?
Something like this?
$client = new \Elasticsearch\Client();
$params = [
'index' => 'default',
'type' => 'books'
'body' => [
'multi_match' => [
'query' => 'Moby Dick',
'fields' => ['title^3', 'author']
]
]
];
$collection = new \Elasticquent\ElasticquentResultCollection($client->search($params), new Book);
The title
field is three times as important as the author
field.
Cheers,
Tortue Torche
Hello!
Im doing some queries in ES through laravel and I've made this query to remove duplicates :
$json = '{
"aggs":{
"dedup" : {
"terms":{
"field": "name"
},
"aggs":{
"dedup_docs":{
"top_hits":{
"size":1
}
}
}
}
}
}';
Now I need to get a collection. I've tried in this way but it doesn't work:
$search_params = array(
'index' => 'cif.observables-*',
'size' => 25000,
'search_type' => 'count'
);
$search_params['body'] = $json;
$cifs = new \Elasticquent\ElasticquentResultCollection($client->search($search_params), new \App\CustomModels\Cif);
In the blade page instead :
@foreach($cifs as $cif_element)
I don't receive anything.. blank page. If I make the query without the aggregation it will work.
Thanks in advance,
Danilo
When I try to use search() I get the error: Undefined index: aggregations
Line 26 in /vendor/fairholm/elasticquent/src/ElasticquentResultCollection.php
$this->aggregations = $results['aggregations'];
I am using facetflow.io, a hosted elasticsearch.
Their url have an API KEY prepend to the cluster url, such as:
https://apikey:@example.azure.facetflow.io
When I put in this URL to the config.hosts, facetflow returned error 401, authentication failed.
No problem when I was using aws elasticsearch, as they doesn't prepend any credential to the url.
So I wonder is this a problem with elasticquent or there are some problem with my server?
regards,
Hi @adamfairholm,
I don't know if you would be up for merging this in, but I thought there were some things missing from this great package. Eager loading relationships and also indexing using chunking, more specifically the reindex
and addAllToIndex
not chunking. I have made these and some other changes on a fork. If you get some time please have a look and let me know if its something you would be happy to merge in and I will make a pull request.
Is it possible to search multiple types/models at the same time with Elasticquent?
Hi adamfairholm, thanks for providing this package. It gave me quite a quick entry into using Elasticsearch and Laravel compared to using Symfony 2 and Elastica which took me longer to wrap my head around.
In the documentation, under searching, you listed the parameters to the searchByQuery method and the last one was sort. I have however gone through your code and seen that the last parameter is offset and there is nowhere in the code where sorting is implemented. Is this an omission? How can I pass a sort query to elasticsearch via Elasticquent?
Thanks
Steve
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.